Sorry this is a very newbie question, but I just can't seem to get it to work.

对不起,这是一个非常新手的问题,但我似乎无法让它工作。

in my bash script, I have

在我的bash脚本中,我有

python=/path/to/python
script=$1
exec $python $script "$@"

How would I pass an argument, say -O to the python interpreter? I have tried:

我如何传递一个参数,比如说-O到python解释器?我努力了:

exec $python -O $script "$@"

exec $ python -O $ script“$ @”

And have tried changing python variable to "/path/to/python -O", as well as passing -O to the script, but every time i do any of these three, I get import errors for modules that succeed when I remove the -O.

并尝试将python变量更改为“/ path / to / python -O”,以及将-O传递给脚本,但每次我执行这三个中的任何一个时,我会在删除时取得成功的模块导入错误-O。

So my question is how to tell the python interpreter to run with -O argument from a bash script?

所以我的问题是如何告诉python解释器使用bash脚本中的-O参数运行?

Thanks.

谢谢。

1 个解决方案

#1


1

You should shift your positional parameters to the left by 1 to exclude your script which is in the first arguments from being included to the arguments for python.

您应该将位置参数向左移动1,以排除第一个参数中的脚本被包含到python的参数中。

#!/bin/sh
python=/path/to/python
script=$1; shift
exec "$python" -O "$script" "$@"

Then run the script as bash script.sh your_python_script arg1 arg2 ... or sh script.sh your_python_script arg1 arg2 ....

然后将脚本运行为bash script.sh your_python_script arg1 arg2 ...或者sh script.sh your_python_script arg1 arg2 ....

更多相关文章

  1. 是否可以使用argparse来捕获任意一组可选参数?
  2. Python定义函数时,不同参数类型的传递
  3. Python语言特性之1:函数参数传递
  4. jira python oauth:如何获取身份验证的参数?
  5. Python——函数 8、可变长参数
  6. Python脚本如何获取当前环节和用户等信息
  7. python函数不定长参数
  8. python mysql 导出到mongodb脚本
  9. 关于Python的属性、参数、方法的解释、区别

随机推荐

  1. android开发之权限问题整理
  2. Android高手进阶教程(九)之----Android H
  3. Android 虚拟摇杆,多种模式回调,返回距离级
  4. Android TV蓝牙模块
  5. Android 服务端开发之开发环境配置
  6. Android 实现气泡布局/弹窗,可控制气泡尖
  7. SurfaceFlinger学习之路(一)View的绘制流程
  8. Android快速滚动
  9. androidmanifest.xml高级属性解析
  10. Intellij下的android实践