python - 允许我的 python 脚本的 Makefile?

标签 python shell makefile

我有一个名为“myprogram.py”的 python 脚本和一个名为“myprogram”的 shell 脚本来运行它

# "myprogram"

#!/bin/sh
python myprogram.py

我创建这个 shell 脚本是因为我想像这样运行我的程序:

./myprogram arg1 arg2

但是,当我这样做时,出现“权限被拒绝”错误。

我知道我需要输入“chmod 755 myprogram”来授予权限,但我想这样做

在我的 makefile 中而不是让用户手动输入 chmod。

换句话说,我想要我的 makefile 以便输入

./make

运行“chmod 755 myprogram”

有没有办法做到这一点?我的 makefile 的内容应该是什么?

谢谢

最佳答案

尝试将类似这样的内容放入Makefile:

all: myprogram
    chmod 755 myprogram

myprogram 注册为 all 目标的依赖项。

请注意,第二行应该以硬制表符开头,而不是空格,因为 Makefile 对缩进非常讲究。

关于shell脚本:有两种写法。

python myprogram.py $1 $2

这会将脚本的前两个参数传递给 python 程序。

但是,如果你这样做

python myprogram.py $@

然后传递给 shell 脚本的所有参数都将传递给 python 程序。

关于python - 允许我的 python 脚本的 Makefile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20508606/

相关文章:

python - 在 Win7 64 位、Python 2.6.4 中安装 PIL (Python Imaging Library)

python - 如何计算有多少项出现一次、两次、三次……?

linux - 运行文件夹中的所有 shell 脚本

python - Flask SQLAlchemy 查询,指定列名

python - 将 x 替换为 y,如果没有 x,则附加 y

shell - 如何在 Awk 中输出以空字符结尾的字符串?

java - 如何作为 Web 服务安全地执行 shell 命令

c - 尝试编译 TPC-H Benchmark 并返回此错误 ld : library not found for -lgcc

c++ - 强制 makefile 构建源代码两次

c++ - 在 makefile 的子目录中链接对象构建