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?

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
1
  • 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