| calc(1) | General Commands Manual | calc(1) |
NAME¶
calc - arbitrary precision calculatorSYNOPSIS¶
calc [-c] [-C] [-d][-D calc_debug[:resource_debug[:user_debug]]]
DESCRIPTION¶
- -c
- Continue reading command lines even after a scan/parse
error has caused the abandonment of a line. Note that this option only
deals with scanning and parsing of the calc language. It does not deal
with execution or run-time errors.
For example:
calc read many_errors.cal
will cause calc to abort on the first syntax error, whereas:
calc -c read many_errors.cal
will cause calc to try to process each line being read despite the scan/parse errors that it encounters.By default, calc startup resource files are silently ignored if not found. This flag will report missing startup resource files unless -d is also given.
- -C
- Permit the execution of custom builtin functions. Without
this flag, calling the custom() builtin function will simply generate an
error.
Use of this flag may cause calc to execute functions that are non-standard and that are not portable. Custom builtin functions are disabled by default for this reason.
- -d
- Disable the printing of the opening title. The printing of
resource file debug and informational messages is also disabled as if
config("resource_debug", 0) had been executed.
For example:
calc "read qtime; qtime(2)"
will output something like:
qtime(utc_hr_offset) defined It's nearly ten past six.
whereas:
calc -d "read qtime; qtime(2)"
will just say:
It's nearly ten past six.
This flag disables the reporting of missing calc startup resource files.
- -D calc_debug[:resource_debug[:user_debug]]
- Force the initial value of config("calc_debug"),
config("resource_debug") and config("user_debug").
The : separated strings are interpreted as signed 32 bit integers. After an optional leading sign a leading zero indicates octal conversion, and a leading ``0x'' or ``0X'' hexadecimal conversion. Otherwise, decimal conversion is assumed.By default, calc_debug is 0, resource_debug is 3 and user_debug is 0.For more information use the following calc command:
help config
- -e
- Ignore any environment variables on startup. The getenv()
builtin will still return values, however.
- -f
- This flag is required when using calc in shell script
mode. It must be at the end of the initial #! line of the
script.
This flag is normally only at the end of a calc shell script. If the first line of an executable file begins #! followed by the absolute pathname of the calc program and the flag -f as in:
#!/usr/bin/calc [other_flags ...] -f
the rest of the file will be processed in shell script mode. See SHELL SCRIPT MODE section of this man page below for details.The actual form of this flag is:
-f filename
On systems that treat an executable that begins with #! as a script, the path of the executable is appended by the kernel as the final argument to the exec() system call. This is why the -f flag at the very end of the #! line.It is possible use -f filename on the command line:
calc [other_flags ...] -f filename
This will cause calc to process lines in filename in shell script mode.Use of -f implies -s. In addition, -d and -p are implied if -i is not given.
- -h
- Print a help message. This option implies -q. This
is equivalent to the calc command help help. The help facility is
disabled unless the mode is 5 or 7. See -m.
- -i
- Become interactive if possible. This flag will cause
calc to drop into interactive mode after the calc_cmd
arguments on the command line are evaluated. Without this flag,
calc will exit after they are evaluated.
For example:
calc 2+5
will print the value 7 and exit whereas:
calc -i 2+5
will print the value 7 and prompt the user for more calc commands.
- -m mode
- This flag sets the permission mode of calc. It
controls the ability for calc to open files and execute programs.
Mode may be a number from 0 to 7.
The mode value is interpreted in a way similar to that of the chmod(1) octal mode:
0 do not open any file, do not execute progs 1 do not open any file 2 do not open files for reading, do not execute progs 3 do not open files for reading 4 do not open files for writing, do not execute progs 5 do not open files for writing 6 do not execute any program 7 allow everything (default mode)
If one wished to run calc from a privileged user, one might want to use -m 0 in an effort to make calc somewhat more secure.Mode bits for reading and writing apply only on an open. Files already open are not effected. Thus if one wanted to use the -m 0 in an effort to make calc somewhat more secure, but still wanted to read and write a specific file, one might want to do in sh(1), ksh(1), bash(1)-like shells:
calc -m 0 3<a.file
Files presented to calc in this way are opened in an unknown mode. Calc will attempt to read or write them if directed.If the mode disables opening of files for reading, then the startup resource files are disabled as if -q was given. The reading of key bindings is also disabled when the mode disables opening of files for reading.
- -O
- Use the old classic defaults instead of the default
configuration. This flag as the same effect as executing
config("all", "oldcfg") at startup time.
NOTE: Older versions of calc used -n to setup a modified form of the default calc configuration. The -n flag currently does nothing. Use of the -n flag is now deprecated and may be used for something else in the future.
- -p
- Pipe processing is enabled by use of -p. For
example:
calc -p "2^21701-1" | fizzbin
In pipe mode, calc does not prompt, does not print leading tabs and does not print the initial header. The -p flag overrides -i.
- -q
- Disable the reading of the startup scripts.
- -s
- By default, all calc_cmd args are evaluated and
executed. This flag will disable their evaluation and instead make them
available as strings for the argv() builtin function.
- -u
- Disable buffering of stdin and stdout.
- -v
- Print the calc version number and exit.
- --
- The double dash indicates to calc that no more options
follow. Thus calc will ignore a later argument on the command line even if
it starts with a dash. This is useful when entering negative values on the
command line as in:
calc -p -- -1 - -7
calc 23 + 47
calc 23 * 47calc -23 + 47
calc '23 * 47'calc "print sqrt(2), exp(1)"
calc '(-23 + 47)'
calc -- -23 + 47calc -q -- -23 + 47
print 27!^2
print 27! ^2 or print 27!^2
calc read myfile
./myfile ./myfile.cal /usr/lib/myfile /usr/lib/myfile.cal /usr/share/calc/custom/myfile /usr/share/calc/custom/myfile.cal
calc 3<open_file 4<open_file2
help help help overview help usage help environment help config
#!/usr/bin/calc [other_flags ...] -f
#!/usr/bin/calc -q -f
#
# 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;
chmod +x /tmp/mersenne
/tmp/mersenne 127
2^127-1 = 170141183460469231731687303715884105727
2^eval(argv(0))-1
2^argv(0)-1
help types
help variable
~/.calcrc
For more information use the following calc command:
help file
help command
FILES¶
- /usr/bin/calc
- calc binary
- /usr/share/doc/apcalc/examples/*
- calc shell scripts
- /usr/lib/*.cal
- calc standard resource files
- /usr/lib/help/*
- help files
- /usr/lib/bindings
- non-GNU-readline command line editor bindings
- /usr/include/calc/*.h
- include files for C interface use
- /usr/lib/libcalc.a
- calc binary link library
- /usr/lib/libcustcalc.a
- custom binary link library
- /usr/share/calc/custom/*.cal
- custom resource files
- /usr/share/calc/custhelp/*
- custom help files
ENVIRONMENT¶
- CALCPATH
- A :-separated list of directories used to search for calc
resource filenames that do not begin with /, ./ or ~.
Default value: .:./cal:~/.cal:/usr/local/share/calc:/usr/share/calc:/usr/share/calc/custom
- CALCRC
- On startup (unless -h or -q was given on the command line),
calc searches for files along this :-separated environment
variable.
Default value: /usr/share/calc/startup:/usr/local/share/calc/startup:~/.calcrc:./.calcinit
- CALCBINDINGS
- On startup (unless -h or -q was given on the
command line, or -m disallows opening files for reading),
calc reads key bindings from the filename specified by this
environment variable. The key binding file is searched for along the
$CALCPATH list of directories.
Default value: bindingThis variable is not used if calc was compiled with GNU-readline support. In that case, the standard readline mechanisms (see readline(3)) are used.
CREDIT¶
COPYING / CALC GNU LESSER GENERAL PUBLIC LICENSE¶
help copyright help copying help copying-lgpl
Free Software Foundation, Inc. 51 Franklin Street Fifth Floor Boston, MA 02110-1301 USA
Copyright (C) year David I. Bell Copyright (C) year David I. Bell and Landon Curt Noll Copyright (C) year David I. Bell and Ernest Bowen Copyright (C) year David I. Bell, Landon Curt Noll and Ernest Bowen Copyright (C) year Landon Curt Noll Copyright (C) year Ernest Bowen and Landon Curt Noll Copyright (C) year Ernest Bowen
Copyright (C) 1999 Landon Curt Noll
CALC MAILING LIST / CALC UPDATES / ENHANCEMENTS¶
calc-tester-request at asthe dot com
calc mailing list subscription
subscribe calc-tester address end name your_full_name
BUG REPORTS / BUG FIXES¶
calc-bugs at asthe dot com [[ NOTE: Replace 'at' with @, 'dot' is with . and remove the spaces ]] [[ NOTE: The EMail address uses 'asthe' and the web site URL uses 'isthe' ]]
calc bug report
help bugs
CALC WEB SITE¶
www.isthe.com/chongo/tech/comp/calc/
| ^..^ | 2007-02-06 |