位置パラメータを使用して新しいシェルを起動する

位置パラメータを使用して新しいシェルを起動する

Pythonでは、位置引数を使用してセッションを開始できます。

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

しかし、これはシェルでは不可能に見えます。

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

位置パラメータを使用して新しいシェルを起動するには?

ベストアンサー1

このオプションを使用できます-s。 ~からPOSIXの説明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.

だから:

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

おすすめ記事