热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

为什么命令没有在bash中使用管道获取输入?-Whyisthecommandnotgettngtheinputwithpipeinbash?

IamtryingtodosomethingsimpleinbashbutIcannotgetittowork.Ihavedefinedthevariable:

I am trying to do something simple in bash but I cannot get it to work. I have defined the variable:

我试图在bash中做一些简单的事情,但我无法让它工作。我已定义变量:

 export devcluster2="10.122.22.22"

in my .bashrc. When I type:

在我的.bashrc中。当我输入:

echo $devcluster2 I get as expected:

echo $ devcluster2我按预期得到:

10.122.22.22

now I want to do:

现在我想做:

echo '$devcluster2' | ssh

but I get

但我明白了

usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
       [-D [bind_address:]port] [-e escape_char] [-F configfile]
       [-I pkcs11] [-i identity_file]
       [-L [bind_address:]port:host:hostport]
       [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
       [-R [bind_address:]port:host:hostport] [-S ctl_path]
       [-W host:port] [-w local_tun[:remote_tun]]
       [user@]hostname [command]

I want to understand why the ssh doesn't get the output of echo as an input? and how can I get it to work?

我想了解为什么ssh没有将echo的输出作为输入?我怎样才能让它发挥作用?

1 个解决方案

#1


To ssh to a host, you use:

要ssh到主机,您使用:

ssh 10.122.22.22

If you want to ssh to a host in a variable, you therefore use:

如果要ssh到变量中的主机,则使用:

ssh "$devcluster2"

Meanwhile, echo text | command is like running command and then typing in "text". If you to run ssh by itself and wait for an opportunity to enter text, it fails just like it does in your script:

同时,回声文本|命令就像运行命令然后输入“text”。如果你自己运行ssh并等待机会输入文本,它就会像你在脚本中那样失败:

$ ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
...

推荐阅读
author-avatar
好人langren_840
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有