maxx
maxx

Reputation: 163

Start sage CLI with init.sage

So I am playing around with Sage and Python a bit.

But I always end up after changing a file with

CTRL-D
> sage
sage: load("init.sage")

is there a way to start the Sage CLI with the init-file preloaded?

or, alternatively, can I call sage init.sage and end up in the Sage CLI?

Upvotes: 1

Views: 391

Answers (1)

Samuel Lelièvre
Samuel Lelièvre

Reputation: 3453

The "Sage startup scripts" page in the SageMath reference manual mentions the SAGE_STARTUP_FILE environment variable which controls which file is used as initialisation file.

If you have a file init.sage in directory my_dir, change to my_dir and run:

$ SAGE_STARTUP_FILE='init.sage' sage

and Sage will use this local init.sage file instead of the one in your DOT_SAGE directory.

Illustration:

$ echo "print('\n   Using custom init file\n')" > my_init.sage
$ SAGE_STARTUP_FILE='my_init.sage' sage -q

   Using custom init file

sage: 

Notes:

  • echo "stuff" > my_file will erase and replace my_file if a file with that name is present,
  • sage -q starts Sage in "quiet" mode, i.e. without displaying the banner.

Upvotes: 2

Related Questions