例如
ssh root@me -- cat /etc/hostname -- cat /etc/hostname我期望它输出:
me me但它输出
me me cat: cat: No such file or directory我知道双破折号意味着结束解析选项,为什么它提高cat: cat: No such file or directory
for example
ssh root@me -- cat /etc/hostname -- cat /etc/hostnameI expect it output:
me mebut it output
me me cat: cat: No such file or directoryI know the double-dash means ending parsing option, why it raise cat: cat: No such file or directory
最满意答案
--表示选项解析结束。 之后没有任何东西--将被视为一种选择,即使它以短划线开头。 例如, ls -l将以长格式打印文件列表,而ls -- -l将查找名为-l的文件。
ssh root@me -- cat /etc/hostname -- cat /etc/hostname这将连接到远程服务器并运行以下命令:
cat /etc/hostname -- cat /etc/hostname这是一个单一的猫命令。 跳过-- ,这相当于写作:
cat /etc/hostname cat /etc/hostname它打印/etc/hostname ,这就是me 。 然后它会尝试打印不存在的文件cat ,并给出错误cat: cat: No such file or directory 。 程序cat抱怨文件cat不存在。 然后再次打印/etc/hostname 。
如果你想用ssh执行多个命令,请执行以下操作:
ssh root@me 'cat /etc/hostname; cat /etc/hostname'或这个:
ssh root@me <<CMDS cat /etc/hostname cat /etc/hostname CMDS-- signals the end of option parsing. Nothing after -- will be treated as an option, even if it begins with a dash. As an example, ls -l will print a file listing in long format while ls -- -l looks for a file named -l.
ssh root@me -- cat /etc/hostname -- cat /etc/hostnameThis sshes to a remote server and runs the command:
cat /etc/hostname -- cat /etc/hostnameThat is a single cat command. Skipping over the --, it's equivalent to writing:
cat /etc/hostname cat /etc/hostnameIt prints /etc/hostname, which is me. It then tries to print the file cat, which doesn't exist, giving the error cat: cat: No such file or directory. The program cat is complaining that the file cat doesn't exist. Then it prints /etc/hostname again.
If you want to execute multiple commands with ssh, do this:
ssh root@me 'cat /etc/hostname; cat /etc/hostname'or this:
ssh root@me <<CMDS cat /etc/hostname cat /etc/hostname CMDS更多推荐
发布评论