全部:
有一个shell脚本.sh:
#/bin/bash -x -n
source /etc/profile
和一个test.c程序使用system((函数来调用这个脚本:
#include <stdio.h>
int main(void)
{
system("/data/nan/a.sh");
return 0;
}
我发现当直接在控制台中调用a.sh时:
./a.sh
没事。
但是执行c程序:
./test
它打印"来源:未找到"。
我知道原因可能是system((函数使用/bin/sh来执行.sh脚本。但我添加了"#/bin/bash"添加了.sh的开头。为什么会发生这种情况?提前非常感谢!
谨致问候
南晓
您在shebang:中缺少一个!
#!/bin/bash -x -n
^