如何禁用EOF
heredoc中的命令替换?
#!/bin/bash
executableFile="executableFile.sh"
firstFolder="blablabla"
cat <<EOF >$executableFile
secondFolder="blablabla2"
if [ $(cat something) == "blub" ]; then
echo $firstFolder
echo $secondFolder
fi
EOF
if子句中的值应该在执行executableFile
时被请求引用'EOF'
将禁用所有特殊字符,并按字面意思处理。
cat <<'EOF' >$executableFile
secondFolder="blablabla2"
if [ $(cat something) == "blub" ]; then
echo $firstFolder
echo $secondFolder
fi
EOF
我还建议双引号引用所有变量展开。这并不总是必要的,但通常是必要的,而且这是一个好习惯。
cat <<'EOF' >"$executableFile"
secondFolder="blablabla2"
if [ "$(cat something)" == "blub" ]; then
echo "$firstFolder"
echo "$secondFolder"
fi
EOF