3

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.

Orat
  • 4,065
  • 1
    Having never used scripts in GAP like this, I don't know why it behaves this way. The question does not seem to really be on topic for this site, however, as it is about the workings of GAP itself, rather than how to do some mathematics in GAP. – Tobias Kildetoft Aug 26 '13 at 10:08
  • @TobiasKildetoft I got your point. I guess that's why some people vote to close this question. However this is the only site that I know an answer may be obtained (People here might familiar with GAP). I would really appreciate if someone tell me what's the problem, or where an answer is likely to obtain. – Orat Aug 26 '13 at 10:15
  • 2
    I usually write the scripts in a text file and Read(...) them into GAP. Is a possible alternative for you? I didn't realise this feature was even present. – Douglas S. Stones Aug 26 '13 at 10:17
  • @DouglasS.Stones Thank you! It works! I'm still a bit curious about the previous question. If someone know it, please tell me. – Orat Aug 26 '13 at 10:23
  • 3
    I believe the all caps version of quit does work. Replace the last line with QUIT; – Jack Schmidt Aug 26 '13 at 13:21
  • 1
    @JackSchmidt Thank you. It work! This is the one that I want. – Orat Aug 26 '13 at 14:29

3 Answers3

4

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.

Orat
  • 4,065
Olexandr Konovalov
  • 7,002
  • 2
  • 34
  • 72
3

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(...).

  • 1
    Thank you for answer. But quit mode appears to prevent to printing something like "gap>". As I wrote in the question, typing those commands separately works... – Orat Aug 26 '13 at 10:37
1

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.

Orat
  • 4,065