Ask Your Question

slcoleman's profile - activity

2020-01-10 23:44:03 +0200 commented question Running Sage in Bash

I am just learning sage, but there is yet another way to envoke sage that is even more bash-like. Assuming that sage is installed in "/usr/bin/sage" you can do:

$ cat ./sagetest.sage
#!/usr/bin/sage 
import sys
args = len(sys.argv)
if args == 2:
   arg1 = int(sys.argv[1]) # read command argument
   print(arg1) # do something with command argument

f = sin(x) / x
d = diff(f, x)
show(d)
..
Note the '#!/path/to/sage' must be on the first line of the file
You must also make the file executable before it can be run the first time
$ chmod 755 ./sagetest.sage

Now you can run the file with "./sagetest.sage" or from in your PATH environment, while even with passing it arguments like in python:
$ ./ssagetest.sage 123