2013-03-06 74 views
-2

所有:
有一个外壳脚本a.sh:使用系统()来执行bash脚本输出:源:找不到

#/bin/bash -x -n 

source /etc/profile 

和test.c的程序使用系统()函数调用这个脚本:

#include <stdio.h> 
int main(void) 
{ 
    system("/data/nan/a.sh"); 
    return 0; 
} 

我在控制台直接找到时调用a.sh:

./a.sh 

这是OK 。

但执行C程序:

./test 

它打印 “来源:找不到”。

我知道原因可能是system()函数使用/ bin/sh来执行a.sh脚本。但我添加“#/ bin/bash”添加a.sh的开头。为什么会发生?首先十分感谢!

问候
难消

回答

4

你缺少的家当一个!

#!/bin/bash -x -n 
^