Ubuntu中的"是"

4 bash ubuntu

如何在Ubuntu中包含hypen或dash字符(-)作为参数yes

在FreeBSD中,我可以这样做:

$ yes "-tcp" | head -n 2
-tcp
-tcp
Run Code Online (Sandbox Code Playgroud)

但是在Ubuntu中,我收到一个错误:

$ yes "-tcp" | head -n 2
yes: invalid option -- 't'
Try `yes --help' for more information.
Run Code Online (Sandbox Code Playgroud)

Sha*_*mer 10

我认为这会奏效:

$ yes -- "-tcp" | head -n 2
Run Code Online (Sandbox Code Playgroud)

双破折号告诉yes停止解析选项.


Nou*_*him 5

使用yes -- -tcp。该--会停止参数处理。

noufal@sanitarium% yes -- "-tcp" | head -n 2
-tcp
-tcp
Run Code Online (Sandbox Code Playgroud)