在 makefile 中将 env var 作为可选参数传递
Pass env var in makefile as optional
我在 makefile 中有一个执行 bash 脚本的命令:
test:
./script.sh
该脚本实现了 getopts,因此可以这样调用:
./script.sh -n 10
在bash中可以通过以下方式完成什么:
./script.sh ${n:+ -n\ "${n}"}
但是当我将这个结构放入 makefile 时,它会生成空字符串。
test:
./script.sh ${n:+ -n\ "${n}"}
而且我不能简单地使用 ./scipt.sh $(n)
因为我需要 -n
前缀。
感谢您的任何建议。
$
在makefile中有特殊的含义,因为it is used for make
variable references。
你的食谱命令中的 ${n:+ -n\ "${n}"}
部分被 make
扩展(而不是 bash
),这导致一个空字符串,这就是 bash
收到:
./script.sh
不过,您可以 转义 $
,方法是在其前面添加一个额外的 $
:
test:
./script.sh $${n:+ -n\ "$${n}"}
这样,bash
就会收到下面的命令来执行:
./script.sh ${n:+ -n\ "${n}"}
我在 makefile 中有一个执行 bash 脚本的命令:
test:
./script.sh
该脚本实现了 getopts,因此可以这样调用:
./script.sh -n 10
在bash中可以通过以下方式完成什么:
./script.sh ${n:+ -n\ "${n}"}
但是当我将这个结构放入 makefile 时,它会生成空字符串。
test:
./script.sh ${n:+ -n\ "${n}"}
而且我不能简单地使用 ./scipt.sh $(n)
因为我需要 -n
前缀。
感谢您的任何建议。
$
在makefile中有特殊的含义,因为it is used for make
variable references。
你的食谱命令中的 ${n:+ -n\ "${n}"}
部分被 make
扩展(而不是 bash
),这导致一个空字符串,这就是 bash
收到:
./script.sh
不过,您可以 转义 $
,方法是在其前面添加一个额外的 $
:
test:
./script.sh $${n:+ -n\ "$${n}"}
这样,bash
就会收到下面的命令来执行:
./script.sh ${n:+ -n\ "${n}"}