简体   繁体   English

在shell脚本中运行python命令行参数

[英]run python command line arguments in shell script

I have a script which takes in few arguments 我有一个包含几个参数的脚本

./hal --runtest=example

where example = /home/user/example.py 其中example = /home/user/example.py

how can I pass these arguments in shell script? 如何在Shell脚本中传递这些参数?

I'm having trouble figuring out what you're asking, but assuming your question is "How can a shell script pass dynamic arguments to a command that happens to be written in Python" and you are using a Bourne-family shell (very likely), the simplest correct answer would be 我在弄清楚您要问的问题时遇到了麻烦,但是假设您的问题是“ shell脚本如何将动态参数传递给恰好用Python编写的命令”,并且您正在使用Bourne系列shell(很有可能),最简单的正确答案是

example=/home/user/example.py
./hal "--runtest=$example"

The shell will resolve the quoting and the script will see --runtest=/home/user/example.py without breaking if you later decide to pass in a path containing spaces. 如果您以后决定传递包含空格的路径,则Shell将解决引用,脚本将看到--runtest=/home/user/example.py不会中断。

Take a look a the following: 看一下以下内容:

http://lowfatlinux.com/linux-script-variables.html http://lowfatlinux.com/linux-script-variables.html

It is Bash specific though and as per comments above not sure which shell you're using. 它是特定于Bash的,并且根据上面的注释,不确定您使用的是哪个Shell。

在这里,您将找到有关如何将参数传递给Shell脚本的所有信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM