【发布时间】:2018-02-04 21:57:59
【问题描述】:
我编译我的项目:
debug=yes make -j4 或 debug=no make -j4
调试变量更改了 Makefile 中的一些编译器标志
我没有在 shell 中重复输入这个,而是编写了这个脚本(我们称之为daemon):
#!/bin/bash
inotifywait -q -m -e close_write `ls *.c* *.h*` |
while read; do
make -j4
done
所以我只做./daemon,它会在写入文件时自动构建。
但是,我希望能够像这样将debug=no make -j4 传递给./daemon 脚本:
./daemon debug=no make -j4
所以我修改了脚本:
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage `basename $0` [COMMAND]"
exit 1;
fi
inotifywait -q -m -e close_write `ls *.c* *.h*` |
while read; do
"$@"
done
这适用于./daemon make -j4,但是当我说daemon debug=no make -j4 时出现以下错误:
./daemon: line 9: debug=no: command not found
我怎样才能使debug=no 被识别为变量而不是daemon 脚本中的命令?
谢谢
【问题讨论】:
-
不要这样使用
ls;只需直接使用 glob,如inotifywait -q -m -e close_write *.c* *.h* | ...。
标签: bash shell makefile environment-variables gnu-make