How to quit GAP script?

817 Views Asked by At

I'm new to GAP and have some trouble with its script. Here is the script that I wrote: foo.gap

#!/usr/bin/gap -q
Display(1 + 1);
quit;

I expected if I type "./foo.gap" then it displays 2 and returns control:

$ ./foo.gap
2
$

However it doesn't return control as I expected; it still waiting commands (that is, typing "Display(2 + 3);" returns 5, for example).

$ ./foo.gap
2
Display(2 + 3);
5

It seems that, however, typing these separately works.

$ gap -q
Display(1 + 1);
2
quit;
$

Would you please help me? What's wrong with the first script, foo.gap? Thank you.

3

There are 3 best solutions below

0
On BEST ANSWER

One needs to redirect the input to GAP - this is why cat foo.gap | gap -q works. One of recipes could be to use the following:

#!/bin/sh
gap -b -q << EOI
Display(1 + 1);
quit;
EOI

Here -b suppresses the banner and -q enables the "quiet" mode, so the script will print only GAP's output.

Note, however, that unless you have specific goals in mind which require calling GAP from such a script, you may also put the GAP code into the text file, say, myfile.g, and then read it into GAP like in the examples here

gap myfile.g
gap -b /path/to/this/file/myfile.g 

or start GAP and call Read(...) from the GAP command line.

P.S. Please note that there are well-established support channels for GAP users such as GAP Forum and GAP Support where a question on GAP might be noticed quicker by a larger number of GAP users and developers of GAP and its packages; therefore (dependently on the question) GAP Forum and GAP Support may happen to be more suitable place for asking.

1
On

According to gap -h, the -q flag enables quiet mode:

  -q          enable/disable quiet mode

This is probably self-explanatory: it looks like this just prevents GAP from printing to the screen.

Scripts can be read in from a text file using Read(...).

0
On

Although the following doesn't answer the question directly, I found a way to accomplish similar things.

cat foo.gap | gap -q

Still, I don't understand why this works and why the previous way doesn't. I would appreciate if someone pointing out where was wrong.