如何在一个命令行中使用多个双破折号(-) [英] How to use multiple double-dash(--) in one command line

查看:81
本文介绍了如何在一个命令行中使用多个双破折号(-)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如

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

I know the double-dash means ending parsing option, why it raise cat: cat: No such file or directory

推荐答案

--表示选项解析结束. --之后的任何内容都不会被视为选项,即使它以短划线开头也是如此.例如,ls -l将以长格式打印文件列表,而ls -- -l查找名为-l的文件.

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

那是一个简单的cat命令.跳过--,等同于编写:

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

cat /etc/hostname cat /etc/hostname

它打印/etc/hostname,即me.然后,它尝试打印不存在的文件cat,并显示错误cat: cat: No such file or directory.程序猫抱怨文件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.

如果要使用ssh执行多个命令,请执行以下操作:

If you want to execute multiple commands with ssh, do this:

ssh root@me 'cat /etc/hostname; cat /etc/hostname'

或者这个:

ssh root@me <<CMDS
cat /etc/hostname
cat /etc/hostname
CMDS

这篇关于如何在一个命令行中使用多个双破折号(-)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆