我正在嘗試想出一個解決方案來爲腳本執行一些數學函數,因爲bash顯然不能做除整數數學之外的其他任何事情(或者可以即使這樣做?)。如何在Bash腳本中將C++程序的輸出作爲變量使用
我想出來的腳本需要編寫一系列最終將用於模擬程序的宏。我目前只是試圖輸出用作宏參數的粒子源的位置。
的C++程序我寫的是很簡單的,它發生在我和輸出x和y這樣:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
double i;
double theta = 11 * (3.1415926535897932384626/180);
cin >> i;
double b = 24.370;
double y = (b/i)*sin(theta);
double x = (b/i)*cos(theta);
cout << x << " " << y << endl;
return 0;
}
我寫的腳本輸出一堆東西,與宏做我試圖創建的,但我卡上線(標有:(1))需要做這樣的事情...
for i in {1..100}
do
echo "./a.out" #calling the C program
echo "$i" #entering i as input
x = first output of a.out, y = second output a.out #(1) Confused on how to do this part!
echo -n "/gps/position $x $y 0 27.7 cm" > mymacro.mac
做
我知道必須有一個真的很簡單的方法來做到這一點,但我我不確定該怎麼做。我基本上只需要在腳本中使用c程序的輸出作爲變量。
那麼,你是否讓你的腳本工作?下面的答案是否有幫助? – phonetagger 2012-10-05 16:04:19