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