2015-03-13 133 views
0

bash劇本我創建另一個bash腳本啓動的程序:從另一個腳本編寫bash腳本在文字模式

$optionsfile="options.conf"  

tee "launch-script.sh" > /dev/null <<EOF 
#!/bin/bash 
bash $binFile `cat $optionsfile` & 
EOF 

我想輸出腳本launch-script.sh是這樣的:

#!/bin/bash 
bash $binFile `cat options.conf` & 

所以我想讓腳本擴大$optionsfile,但不要執行cat命令。 現在我越來越:

#!/bin/bash 
bash $binFile -ops1 -ops2 -ops3 & 

是否有可能實現這一目標?我做錯了什麼?

編輯:

使用的答案和註釋到目前爲止,我發現了更好的解決方案將使用轉義:

$optionsfile="options.conf"  

tee "launch-script.sh" > /dev/null <<EOF 
#!/bin/bash 
bash $binFile \$(< $optionsfile) & 
EOF 
+1

更好地從heredoc中刪除前導空格:如果您要使用shebang功能,'#!'必須是文件的前2個字符。 – 2015-03-13 13:28:36

+1

請注意,特定於bash的'$( 2015-03-13 13:29:23

回答

3

使用反斜槓防止插補:

tee "launch-script.sh" > /dev/null <<EOF 
    #!/bin/bash 
    bash \$binFile \`cat $optionsfile\` & 
EOF 
+0

你擊敗了我16秒... :-) – 2015-03-13 11:55:35

+0

謝謝,它工作得很好 – Atropo 2015-03-13 13:47:47

2

正常逃脫工作嗎?

tee "launch-script.sh" > /dev/null <<EOF 
    #!/bin/bash 
    bash \$binFile \`cat $optionsfile\` & 
EOF