|
When starting up Magma, various command-line options can be supplied,
and a list of files to be automatically loaded can also be specified.
These files may be specified by simply listing their names as normal
arguments (i.e., without a - option) following the Magma command.
For each such file name, a search for the specified file is conducted,
starting in the current directory, and in directories specified by the
environment variable MAGMA_PATH after that if necessary.
It is also possible to have a startup file, in which one would usually
store personal settings of parameters and variables. The startup file is
specified by the MAGMA_STARTUP_FILE environment variable which
should be set in the user's .cshrc file or similar. This environment
variable can be overridden by the -s option, or cancelled by
the -n option.
The files specified by the arguments to Magma are loaded after the
startup file. Thus the startup file is not cancelled by giving extra file
arguments, which is what is usually desired.
Magma also allows one to set variables from the command line --- if one
of the arguments is of the form var:=val, where var is
a valid identifier (consisting of letters, underscores, or non-initial digits)
and there is no space between var and the :=, then the variable
var is assigned within Magma to the string value val
at the point where that argument is processed. (Functions like
StringToInteger should be used to convert the value to an object of
another type once inside Magma.)
If the -b argument is given to Magma, the opening banner and
all other introductory messages are suppressed. The final "total
time" message is also suppressed. This is useful when sending the
whole output of a Magma process to a file so that extra removing
of unwanted output is not needed.
If the -c argument is given to Magma, followed by a filename,
the filename is assumed to refer to a package source file and the
package is compiled and Magma then exits straight away. This option
is rarely needed since packages are automatically compiled when attached.
If the -d option is supplied to Magma, the licence for the current
magmapassfile is dumped. That is, the expiry date and the valid
hostids are displayed. Magma then exits.
magma -E arguments
If the -e or -E options are used, then the remaining arguments
will be treated as Magma input, and Magma will exit after processing
that input.
This allows Magma to be used more easily from within scripts or pipelines,
where (usually) only a single calculation is desired.
The -E option is equivalent to -b -n -e.
magma -I filename arguments
Specifying the -i or -I options allows Magma to be used
as the interpreter in the "shebang" line of a UNIX script.
This can simplify the bundling of a common Magma calculation into a
script.
In such a case, the filename argument will be provided to Magma by
the operating system and does not need to be specified. It can be
retrieved from within Magma with the GetScriptFilename intrinsic.
The remaining arguments are not processed but are available (as
strings) from the GetScriptArguments intrinsic.
The -I option is equivalent to -b -n -i.
If the -n option is supplied to Magma, any startup file specified by
the environment variable MAGMA_STARTUP_FILE or by the -s
option is cancelled.
If the -r option is supplied to Magma, together with a workspace
file, that workspace is automatically restored by Magma when it starts
up.
If the -s option is supplied to Magma, the given filename
is used for the startup file for Magma. This overrides the
variable of the environment variable MAGMA_STARTUP_FILE if
it has been set. This option should not be used (as it was before),
for automatically loading files since that can be done by just listing
them as arguments to the Magma process.
When starting up Magma, it is possible to specify a seed for the
generation of pseudo-random numbers. (Pseudo-random quantities are
used in several Magma algorithms, and may also be generated
explicitly by some intrinsics.) The seed should be in the range
0 to (2 ^ (32) - 1) inclusive. If -S is not followed by any
number, or if the -S option is not used, Magma selects the seed
itself.
If the -t option is supplied to Magma at the command line,
together with a positive number N, then the number of POSIX threads
is set to N at startup (so this is equivalent to calling SetNthreads(N); after Magma has started).
magma --version
If the -V argument is given to Magma, the version of Magma
is printed, and then Magma exits immediately.
The option --version is equivalent.
By typing the command
magma file1 x:=abc file2
Magma would start up, read the user's startup file specified by
MAGMA_STARTUP_FILE if existent, then read the file file1, then
assign the variable x to the string value "abc", then read
the file file2, then give the prompt.
In this example and the next one, the dollar symbol at the start of a
line indicates the shell prompt, and does not form part of the input to
the shell.
We can direct Magma to perform a specific computation from the
command line using the -e or -E options.
For instance:
$ magma -E 5^2 + 12^2
169
Magma runs, interprets the remaining arguments as input, performs
the associated computations (printing output as appropriate), then exits.
Note that characters that are significant to the shell, such as brackets,
will need to be protected in some fashion; the simplest approach is likely
to enclose the entire command in single quotes.
$ magma -E 'Binomial(10, 4)*Binomial(5, 3)'
2100
Without the use of single quotes the shell will attempt to handle
the brackets itself and raise a syntax error.
Using Magma in the interpreter field of a UNIX script can simplify
the automation of Magma computations.
Suppose we put the following into a file named prod:
#!/usr/local/bin/magma -I
print "3 * 4 =", 3*4;
After making prod executable, we run it, with unsurprising results:
$ prod
3 * 4 = 12
We can modify it as follows to get the values to multiply from the
user-provided arguments:
#!/usr/local/bin/magma -I
args := GetScriptArguments();
a := StringToInteger(args[1]);
b := StringToInteger(args[2]);
printf "%o * %o = %o\n", a, b, a*b;
And now we can vary the arguments to suit our needs of the moment:
$ prod 5 7
5 * 7 = 35
[Next][Prev] [Right] [Left] [Up] [Index] [Root]
|