以文字模式从另一个脚本编写 bash 脚本
Writing a bash script from another script in literal mode
在 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
使用反斜杠防止插值:
tee "launch-script.sh" > /dev/null <<EOF
#!/bin/bash
bash $binFile \`cat $optionsfile\` &
EOF
正常的转义是否有效?
tee "launch-script.sh" > /dev/null <<EOF
#!/bin/bash
bash $binFile \`cat $optionsfile\` &
EOF
在 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
使用反斜杠防止插值:
tee "launch-script.sh" > /dev/null <<EOF
#!/bin/bash
bash $binFile \`cat $optionsfile\` &
EOF
正常的转义是否有效?
tee "launch-script.sh" > /dev/null <<EOF
#!/bin/bash
bash $binFile \`cat $optionsfile\` &
EOF