2

I can't seem to figure out how to use the GAP computer algebra system (for example, if I have a python script, I can do python script.py > /tmp/python_output.csv) I can't seem to find any info in the GAP documentation [I am sure it is there somewhere])

Igor Rivin
  • 4,632
  • 2
  • 23
  • 35
  • 1
    Is `gap script.g` what you're looking for, or do you want a shell script like `check-one-order.sh` from the [GAP Carpentries-style lesson](https://carpentries-incubator.github.io/gap-lesson/discuss/) ? – Olexandr Konovalov Mar 26 '21 at 10:03

2 Answers2

3

Using gap script.g works fine, but it does not terminate GAP at the end, but rather switches to the REPL at the end. To change that, you can end your script with QUIT;. Or, if you use GAP >= 4.11.0, you can add -c 'QUIT;' at the end of the command line to achieve the same effect for any script, without modifying it.

In addition, you may want to turn off the banner with -b and enable quiet mode with -q. Finally, you can use --quitonbreak to disable the break loop so that errors terminate instead of resulting in a hang waiting for user input.

In summary:

gap --quitonbreak -b -q script.g

or if you don't want to end your script with QUIT;, use

gap --quitonbreak -b -q script.g -c 'QUIT;'

If you feel the need to do this a lot, you could wrap this into a little helper shell script gap-batch which looks something like this:

#!/bin/sh
gap --quitonbreak -b -q $* -c 'QUIT;'

If you put this into your PATH, then you can just do

gap-batch script.g
Max Horn
  • 552
  • 4
  • 16
  • The example at https://carpentries-incubator.github.io/gap-lesson/discuss/ also shows how you can pass an argument to the shell script to substitute it into a call of a GAP function. – Olexandr Konovalov Mar 31 '21 at 17:43
1

I use unix redirection :

     gap -q < file.g

to run batch file. It works well.

wkong
  • 41
  • 4