【发布时间】:2023-03-15 07:07:01
【问题描述】:
在 linux bash 中使用 here 脚本在远程服务器上运行命令时,所有行都会打印出来。 cmets如何被抑制?
下面代码的输出应该是:
ls
... (whatever is in this folder)
echo -e this is a test\ndone
this is a testndone
exit
这可能吗? 这样做的原因是命令和 cmets 更复杂,使得输出难以阅读。那应该更漂亮。
#!/bin/bash
ssh -tt hogan@123.123.123.123 <<EOF
# this line get printed
ls
# and this comment also
echo -e this is a test\ndone
# exit ssh
exit
EOF
#end of script
【问题讨论】:
-
为什么不传入一个命令行参数,如果设置,echo 就是你的调试信息。然后你用 if 语句包围你的调试 cmets,检查是否设置了一些标志......说“--debug”或其他东西。