我試圖解決一個問題,我想要一個bash腳本來調用c
程序和一個值從c
程序返回到bach腳本並存儲在一個變量。如何將c程序中的值返回給調用它的後臺腳本?
下面是一個例子(代碼是不是真的寫正確):
bash腳本:
$value = ./foo
echo $value
C程序:
int main() {
//Have a value here that is returned to the variable 'value' in the bash script.
return 0;
}
這可能嗎?
將值打印到stdout然後捕獲它 –
因此,像[this](http://stackoverflow.com/questions/4651437/how-to-set-a-bash-variable-equal-to-the-output -from-A-命令)?如果是這樣,您將需要使用printf語句。 – tonysdg