tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: '/bin/sh -c' with multiple args
Date: Thu, 4 Dec 2025 19:59:54 -0500
From: Jan Schaumann <jschauma%netmeister.org@localhost>
Message-ID: <aTIuigJNKVKuv0y2%netmeister.org@localhost>
| Thanks everybody - this is the part that wasn't
| obvious to me from the description. A curious use
| case, it seems to me.
Not really, -c (to run a short literal script) is a very often used
feature of sh that has been around for a VERY long time. Giving addition
args to that script is a much less often used feature, but can be very
useful.
| I wonder if the manual page could be improved upon here.
It already says, in the "Invocation" section (near the start):
If command line arguments besides the options have been specified, and
neither -c nor -s was given, then the shell treats the first argument as
the name of a file from which to read commands (a shell script). This
also becomes $0 and the remaining arguments are set as the positional
parameters of the shell ($1, $2, etc). Otherwise, if -c was given, then
the first argument, which must exist, is taken to be a string of sh
commands to execute. Then if any additional arguments follow the command
string, those arguments become $0, $1, ... Otherwise, if additional
arguments were given (which implies that -s was set) those arguments
become $1, $2, ... If $0 has not been set by the preceding processing,
it will be set to argv[0] as passed to the shell, which will usually be
the name of the shell itself. If -s was given, or if neither -c nor any
additional (non-option) arguments were present, the shell reads commands
from its standard input.
The relevant part of that is:
Otherwise, if -c was given, then the first argument, which must exist,
is taken to be a string of sh commands to execute.
That "commands" is using the word as it is used elsewhere
And about any extra args in that case:
Then if any additional arguments follow the command string, those
arguments become $0, $1, ...
And recall, this is all about starting sh - not about what happens when
some other command is run.
The description of the -c option says:
-c Read commands from the command_string
operand instead of, or in addition to, from
the standard input.
(forget the "in addition to" part here, that's an obscure ash shell addition).
There is a whole section ("Commands") which describes what that means.
What do you think should be done to improve it?
kre
Home |
Main Index |
Thread Index |
Old Index