2015-03-13 136 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