I don’t understand the difference between:
set youtube=’https://youtube.com’
and
youtube=’https://youtube.com’
With the second one, I’m able to use it in the middle of a command, such as:
cygstart $youtube
and that works.
Why and how are these different? They both set variables?
And, when I don't use the word "set" I have to expand the variable using $?
Thanks.
The two commands are completely unrelated; set youtube='https://youtube.com'
has nothing to do with $youtube
. What it does is, it sets $1
to the whole string 'youtube=https://youtube.com'
.
Per http://www.gnu.org/software/bash/manual/bashref.html#The-Set-Builtin, set
is a shell builtin with three distinct purposes:
set -C
tells the shell that you don't want >
to overwrite existing files (and that you instead want commands to fail if they would otherwise do that); and set +C
tells the shell that never mind, you now want >
to be able to overwrite files again.$1
and $2
and so on, as well as $@
and $*
).Since set youtube='https://youtube.com'
calls set
with exactly one argument, namely youtube=https://youtube.com
, it has the effect of setting the first positional parameter ($1
) to youtube=https://youtube.com
.
Note that youtube='https://youtube.com'
is a somewhat misleading way to write youtube=https://youtube.com
; the single-quotes aren't doing anything here (since the sole purpose of single-quotes is to escape whitespace and special characters, and https://youtube.com
doesn't have any of these).