Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何让命令行解释&;作为字符串,而不显式将其设置为字符串_Python 3.x_Shell - Fatal编程技术网

Python 3.x 如何让命令行解释&;作为字符串,而不显式将其设置为字符串

Python 3.x 如何让命令行解释&;作为字符串,而不显式将其设置为字符串,python-3.x,shell,Python 3.x,Shell,每次我运行脚本并尝试将&符号传递到命令行参数的末尾时,它都会返回我认为是某种进程ID的内容 这是我的剧本: 导入系统 s=sys.argv[1:] 印刷品 我是这样运行的: $ python3 shell.py hello.sh & [2] 3211 ["hello.sh"] 符号&告诉shell自己分叉并在后台运行作业。它还会打印作业编号及其进程ID(PID) 如果您需要有关shell中作业控制的更多信息,请查看 如果希望将其作为参数传递给程序,则需要先用反斜杠将其转义: $ py

每次我运行脚本并尝试将
&
符号传递到命令行参数的末尾时,它都会返回我认为是某种进程ID的内容

这是我的剧本:

导入系统 s=sys.argv[1:] 印刷品 我是这样运行的:

$ python3 shell.py hello.sh &
[2] 3211
["hello.sh"]

符号
&
告诉shell自己分叉并在后台运行作业。它还会打印作业编号及其进程ID(PID)

如果您需要有关shell中作业控制的更多信息,请查看

如果希望将其作为参数传递给程序,则需要先用反斜杠将其转义:

$ python3 test.py  hello.sh \&
['hello.sh', '&']

符号
&
告诉shell自己分叉并在后台运行作业。它还会打印作业编号及其进程ID(PID)

如果您需要有关shell中作业控制的更多信息,请查看

如果希望将其作为参数传递给程序,则需要先用反斜杠将其转义:

$ python3 test.py  hello.sh \&
['hello.sh', '&']