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?


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
  • Perfect! Thank you! – user327359 Jul 9 '19 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy