bash SSH 远程服务器 - 在终端的输出中只显示“echo”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27040260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:49:50  来源:igfitidea点击:

SSH remote server - display only "echo" on output in terminal

linuxbashsshcommandsh

提问by kevas

I have bash script (for example):

我有 bash 脚本(例如):

ssh -t -t [email protected] << EOF
    cd /home/admin
    mkdir test
    echo 'Some text'
    exit 
EOF

Can I display only "echo" command in terminal? It is possible?

我可以在终端中只显示“echo”命令吗?有可能的?

Now all commands are displayed.

现在显示所有命令。

Thank you

谢谢

回答by tripleee

Specifying the commands on standard input with ssh -tcauses the commands to be echoed back, but you don't have to do that.

在标准输入上指定命令 withssh -t会导致命令被回显,但您不必这样做。

ssh -t [email protected] "
    cd /home/admin
    mkdir test
    echo 'Some text'"

(The exitisn't really required or useful, so I left it out.)

(这exit不是真正需要或有用的,所以我把它省略了。)

Use single quotes if you want to prevent the local shell from interpolating variables etc in the string containing the commands.

如果要防止本地 shell 在包含命令的字符串中插入变量等,请使用单引号。

To selectively display an individual command as well as its output, you can use something like

要选择性地显示单个命令及其输出,您可以使用类似

    sh -vc 'echo \"Some text\"'

although the nested quoting can start getting on your nerves pretty quickly.

尽管嵌套引用很快就会让您感到不安。