[Most of this article, except IFS
, also applies to the
C shell. -JP]
The Bourne shell command line can have options like -e
any command returns non-zero status).
It can also have other arguments; these are passed to shell scripts.
You can set new command-line parameters while you're typing interactive
commands (at a shell prompt) or in a shell script.
To reset the command-line parameters, just type set
followed by the new
So, for example, to ask the shell to show expanded versions of command lines
after you type them, set the
(verbose) option (8.17
mail $group1 < message
mail andy ellen heather steve wilma < message
mail $group2 < message
mail email@example.com firstname.lastname@example.org email@example.com < message
cancels the v
option on many Bourne shells.
You can put filenames or any other strings in the command-line parameters
interactively or from a shell script.
That's handy for storing and parsing the output of a UNIX command with
For example, you can get a list of all logged-in users from the parameters
, and so on.
if your system has it.
to strip off everything but the
set `who | cut -c1-8`
> ...do something with each user ($u)...
You can save the original parameters in another variable and reset them
...use new settings...
If the first parameter you set
starts with a dash, like
the shell will treat it as its own option instead of as a string to
put into the command-line parameters.
To avoid this, use
(two dashes) as the first argument to
In this example,
, and the filenames expanded
from the wildcard pattern go into
set -- -e file*
Because the shell parses and scans the new parameters before it stores them,
special characters (8.19
will be interpreted - watch your
You can take advantage of this to parse lines of text into pieces that
aren't separated with the usual spaces and TABs - for instance, a line from a
database with colon-separated
fields - by setting the
variable before the set
If you want to save any special quoting on the original command line,
be careful; the quoting will be lost unless you're clever.
For example, if
used to be John Smith
it'll be split
after it's restored:
will have John
solution might be to use a
for the part of the script where you need to reset the command-line
# reset command-line parameters during subshell only:
some new parameters
...do something with new parameters
# original parameters aren't affected from here on...
One last note: set
, the name of the script file.