在linux bash中使用此脚本在远程服务器上运行命令时,将打印所有行。如何抑制评论?
以下代码的输出应为:
ls
... (whatever is in this folder)
echo -e this is a test\ndone
this is a testndone
exit
这可能吗? 这样做的原因是命令和注释更复杂,导致输出难以阅读。那应该更漂亮。
#!/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
答案 0 :(得分:2)
我通常使用sed
过滤掉评论和空白行。以下内容还将删除同一行上命令后面的注释:
#!/bin/bash
sed 's/[[:blank:]]*#.*//; /^$/d' <<EOF | ssh -tt hogan@123.123.123.123
# this line get printed
ls
# and this comment also
echo -e "this is a test\ndone"
# exit ssh
exit
EOF
答案 1 :(得分:0)
命令后尝试输入
| grep -v "^[[:space:]]*#"
所以,例如,
cat temp.txt | grep -v "^[[:space:]]*#"
答案 2 :(得分:0)
我想你可能会要求这个
grep -v '^[[:space:]]*#' <<EOF | ssh -tt hogan@123.123.123.123
# this line get printed
ls
# and this comment also
echo -e this is a test\ndone
# exit ssh
exit
EOF