44.19 The Bourne Shell set Command
[Most of this article, except
IFS
and The Bourne shell command line can have options like -e (exit if 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 parameters. So, for example, to ask the shell to show expanded versions of command lines after you type them, set the -v (verbose) option ( 8.17 ) :
$
Typing
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
backquotes (
9.16
)
.
For example, you can get a list of all logged-in users from the parameters
You can save the original parameters in another variable and reset them later:
oldparms="$*" set
If the first parameter you
set
starts with a dash, like
set -- -e file* Because the shell parses and scans the new parameters before it stores them, wildcards ( 15.2 ) and other special characters ( 8.19 ) will be interpreted - watch your quoting ( 8.14 ) . 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 IFS ( 35.21 ) variable before the set command.
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
# reset command-line parameters during subshell only: (set
One last note:
set
won't set - |
|