2013-10-07 166 views
0

我在腳本中使用以下行。gnuplot輸入的bash腳本

foo=$1 

bar=$(printf ' , "%s" u ($1):($2) lw 8 ti' ${foo[@]} ${foo[@]} ${foo[@]} ${foo[@]} ) 

bar=${bar:2} 

echo $bar  

這將產生以下行變量酒吧

"rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti 

的價值在於它可以修改腳本,以便輸出爲:

"rdf_inter_fortran_05-25.xvg" u ($1):($2) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($3) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($4) lw 8 ti , "rdf_inter_fortran_05-25.xvg" u ($1):($5) lw 8 ti 
+0

呃..........是嗎? –

+0

我修改了這個問題! –

回答

1

更改您的printf線以下:

bar=$(printf ' , "%s" u ($1):($%s) lw 8 ti' ${foo[@]} "2" ${foo[@]} "3" ${foo[@]} "4" ${foo[@]} "5") 
0

看起來要更換一些新的字符串2美元。 echo $bar之前插入此行:

bar=$(echo $bar | sed 's/$2/$5/4; s/$2/$4/3; s/$2/$3/2;') 

這取代了第四,第三和$ 2與新的各值$ 5,$ 4和$ 3第二發生。