最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

linux - What do the double dashes in expect do? - Stack Overflow

programmeradmin1浏览0评论

I am trying to figure out the difference in below code

#!/usr/bin/env expect
spawn -noecho git_script.sh
expect "Are you sure you want to continue connecting (yes/no/[fingerprint])? "

send "yes\r" 
# below with dashes
send -- "yes\r" 

What is the difference? In the manpage I found:

The -- flag forces the next argument to be interpreted as a string rather than a flag. Any string can be preceded by "--" whether or not it actually looks like a flag. This provides a reliable mechanism to specify variable strings without being tripped up by those that accidentally look like flags. (All strings starting with "-" are reserved for future options.)

But I dont quite understand it.

I am trying to figure out the difference in below code

#!/usr/bin/env expect
spawn -noecho git_script.sh
expect "Are you sure you want to continue connecting (yes/no/[fingerprint])? "

send "yes\r" 
# below with dashes
send -- "yes\r" 

What is the difference? In the manpage I found:

The -- flag forces the next argument to be interpreted as a string rather than a flag. Any string can be preceded by "--" whether or not it actually looks like a flag. This provides a reliable mechanism to specify variable strings without being tripped up by those that accidentally look like flags. (All strings starting with "-" are reserved for future options.)

But I dont quite understand it.

Share Improve this question edited Mar 27 at 23:25 Barmar 784k57 gold badges548 silver badges660 bronze badges asked Mar 27 at 23:09 Stephan KristynStephan Kristyn 15.8k15 gold badges93 silver badges158 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 2

-- is needed when an argument begins with -, but you want it to be treated literally rather than as an option, e.g. to send the string -yes you must write:

send -- "-yes\r"

If the argument doesn't begin with - there's no need, and -- is redundant.

If you're sending the value of a variable you should always use -- in case the value begins with -.

发布评论

评论列表(0)

  1. 暂无评论