我的印象是我可以在GNU makefile中调用bash函数,但是似乎是错误的。这是一个简单的测试,我定义了此功能:
>type lsc
lsc is a function
lsc ()
{
ls --color=auto --color=tty
}
Run Code Online (Sandbox Code Playgroud)
这是我的Makefile:
>cat Makefile
all:
lsc
Run Code Online (Sandbox Code Playgroud)
这是我运行make的过程:
>make
lsc
make: lsc: Command not found
make: *** [all] Error 127
Run Code Online (Sandbox Code Playgroud)
我的印象错了吗?还是有任何环境设置问题?我可以在命令行中运行“ lsc”。
您不能调用Makefile中的bash函数或别名,只能调用二进制文件和脚本。但是,您可以做的是调用交互式bash并指示它调用您的函数或别名:
all:
bash -i -c lsc
Run Code Online (Sandbox Code Playgroud)
例如,如果lsc在中定义了if .bashrc。
使用$*你的bash脚本:
functions.sh
_my_function() {
echo $1
}
# Allows to call a function based on arguments passed to the script
$*
Run Code Online (Sandbox Code Playgroud)
生成文件
test:
./functions.sh _my_function "hello!"
Run Code Online (Sandbox Code Playgroud)
运行示例:
$ make test
./functions.sh _my_function "hello!"
hello!
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3612 次 |
| 最近记录: |