如何在 linux ssh here 脚本中禁止评论
How to suppress comments in linux ssh here script
在远程服务器上的 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
输入命令后尝试输入
| grep -v "^[[:space:]]*#"
例如,
cat temp.txt | grep -v "^[[:space:]]*#"
我想你可能会问这个
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
我一般用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
在远程服务器上的 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
输入命令后尝试输入
| grep -v "^[[:space:]]*#"
例如,
cat temp.txt | grep -v "^[[:space:]]*#"
我想你可能会问这个
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
我一般用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