【发布时间】:2022-01-03 00:01:49
【问题描述】:
我正在尝试使用命令行将脚本的内容保存到文件中,但我注意到当 tee 命令检测到诸如 $(/usr/bin/id -u) 之类的 linux 命令时,它会执行命令而不是而不是按原样保存行。如何避免执行命令并完全按照我输入的方式保存文本?
$tee -a test.sh << EOF
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo You are not running as the root user.
exit 1;
fi;
EOF
if [[ 502 -ne 0 ]]; then
echo You are not running as the root user.
exit 1;
fi;
完整的脚本包含更多行,但我选择了/usr/bin/id -u 作为示例。
【问题讨论】:
-
美元符号在这种情况下具有特殊含义。你可以用反斜杠转义它。 *.com/questions/2500436/…