mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
93 lines
2.7 KiB
Plaintext
93 lines
2.7 KiB
Plaintext
Calc shell scripts
|
|
------------------
|
|
|
|
If an executable file begins with:
|
|
|
|
#!/usr/local/bin/calc -S [-other_flags ...]
|
|
|
|
the rest of the file will be processed in shell script mode.
|
|
Note that -S (UPPER CASE -S) must be the first -flag on the
|
|
``#!'' line. Any other optional ``-other_flags'' must come
|
|
after the -S.
|
|
|
|
In shell script mode the contents of the file are evaluated
|
|
and executed as if they were processed by the read command.
|
|
Any optional ``-other_flags'' will by parsed first followed
|
|
by any arguments given shell script itself.
|
|
|
|
In shell script mode, -s (lower case -s) is always assumed.
|
|
In addition, -d and -p are automatically set if -i is not
|
|
given.
|
|
|
|
For example, if the file /tmp/mersenne:
|
|
|
|
#!/usr/local/bin/calc -S -q
|
|
#
|
|
# mersenne - an example of a calc shell script file
|
|
|
|
/* parse args */
|
|
if (argv() != 1) {
|
|
fprintf(files(2), "usage: %s exp\n", config("program"));
|
|
abort "must give one exponent arg";
|
|
}
|
|
|
|
/* print the mersenne number */
|
|
print "2^": argv(0) : "-1 =", 2^eval(argv(0))-1;
|
|
|
|
is made an executable file by:
|
|
|
|
chmod +x /tmp/mersenne
|
|
|
|
then the command line:
|
|
|
|
/tmp/mersenne 127
|
|
|
|
will print:
|
|
|
|
2^127-1 = 170141183460469231731687303715884105727
|
|
|
|
Note that because -s is assumed in shell script mode and
|
|
non-dashed args are made available as strings via the argv()
|
|
builtin function. Therefore:
|
|
|
|
2^eval(argv(0))-1
|
|
|
|
will print the decimal value of 2^n-1 but
|
|
|
|
2^argv(0)-1
|
|
|
|
will not.
|
|
|
|
For more information use the following calc commands:
|
|
|
|
help usage
|
|
help argv
|
|
help config
|
|
help cscript
|
|
|
|
## Copyright (C) 1999 Landon Curt Noll
|
|
##
|
|
## Calc is open software; you can redistribute it and/or modify it under
|
|
## the terms of the version 2.1 of the GNU Lesser General Public License
|
|
## as published by the Free Software Foundation.
|
|
##
|
|
## Calc is distributed in the hope that it will be useful, but WITHOUT
|
|
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
## Public License for more details.
|
|
##
|
|
## A copy of version 2.1 of the GNU Lesser General Public License is
|
|
## distributed with calc under the filename COPYING-LGPL. You should have
|
|
## received a copy with calc; if not, write to Free Software Foundation, Inc.
|
|
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
##
|
|
## @(#) $Revision: 29.2 $
|
|
## @(#) $Id: script,v 29.2 1999/12/17 10:33:00 chongo Exp $
|
|
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/script,v $
|
|
##
|
|
## Under source code control: 1999/11/30 05:29:48
|
|
## File existed as early as: 1999
|
|
##
|
|
## chongo <was here> /\oo/\ http://reality.sgi.com/chongo/
|
|
## Share and enjoy! :-) http://reality.sgi.com/chongo/tech/comp/calc/
|