I know that contents of double quotes are expanded, whereas the contents of single quotes are not, such that
echo '$1'
gives
$1
where as
echo "$1"
gives
<the argument - blank in this particular example>
the same as
echo $1
However, the question Bash: How to create an alias in .bashrc for awk with parameters led me to wonder why double quotes and not single quotes were used when declaring the alias, thus:
alias cutf="_cutf"
instead of
alias cutf='_cutf'
I would have employed single quotes as in the latter example. Most examples on the web use single too, unless there is some expansion required. However, in this case, no expansion, to my eyes, is apparent. Is it that, in this case, they are interchangeable, or are the double quotes necessary because a function definition is employed?
echo "~"
will not be expanded if quoted either way. In double quotes you will get the$
-expression expanded. In cases where no expansion is effective but you want no splitting to occur, like inecho "hello world"
either quotes are appropriate. In some cases no quotes are necessary (even if often seen), e.g. in assignments likex=value
ory=$var
.