admin管理员组

文章数量:1356940

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

本文标签: linuxWhat do the double dashes in expect doStack Overflow