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

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

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


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

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

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


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

You must log in to answer this question.