如何在一个命令行中使用多个双破折号(

编程入门 行业动态 更新时间:2024-10-27 10:24:55
如何在一个命令行中使用多个双破折号( - )(How to use multiple double-dash(--) in one command line)

例如

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/hostname

I expect it output:

me me

but it output

me me cat: cat: No such file or directory

I 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/hostname

This sshes to a remote server and runs the command:

cat /etc/hostname -- cat /etc/hostname

That is a single cat command. Skipping over the --, it's equivalent to writing:

cat /etc/hostname cat /etc/hostname

It 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

更多推荐

本文发布于:2023-08-04 10:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:破折号   多个   命令行   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!