为什么命令没有在 bash 中使用管道获取输入?
Why is the command not gettng the input with pipe in bash?
我想在 bash 中做一些简单的事情,但我无法让它工作。我已经定义了变量:
export devcluster2="10.122.22.22"
在我的 .bashrc 中。当我输入:
echo $devcluster2
我得到了预期的结果:
10.122.22.22
现在我想做:
echo '$devcluster2' | ssh
但我明白了
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]
我想了解为什么 ssh
没有将 echo 的输出作为输入?我怎样才能让它工作?
要通过 ssh 连接到主机,您可以使用:
ssh 10.122.22.22
如果你想通过 ssh 连接到一个变量中的主机,你可以使用:
ssh "$devcluster2"
与此同时,echo text | command
就像 运行 宁 command
然后输入 "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]
...
我想在 bash 中做一些简单的事情,但我无法让它工作。我已经定义了变量:
export devcluster2="10.122.22.22"
在我的 .bashrc 中。当我输入:
echo $devcluster2
我得到了预期的结果:
10.122.22.22
现在我想做:
echo '$devcluster2' | ssh
但我明白了
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]
我想了解为什么 ssh
没有将 echo 的输出作为输入?我怎样才能让它工作?
要通过 ssh 连接到主机,您可以使用:
ssh 10.122.22.22
如果你想通过 ssh 连接到一个变量中的主机,你可以使用:
ssh "$devcluster2"
与此同时,echo text | command
就像 运行 宁 command
然后输入 "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]
...