0

With Python, I can start a session with positional parameters:

$ python3 - aa
>>> import sys
>>> sys.argv[1]
'aa'

However it does not seem to be possible with shell:

$ sh - aa
sh: aa: No such file or directory

How can I start a new shell with positional parameters?

1 Answer 1

3

You can use the -s option for that. From the POSIX description of sh:

sh -s [-abCefhimnuvx] [-o option]... [+abCefhimnuvx] [+o option]...
       [argument...]

-s
Read commands from the standard input.
If there are no operands and the -c option is not specified, the -s option shall be assumed.

So:

% sh -s foo bar
sh-3.2$ echo "$@"
foo bar
0

You must log in to answer this question.