In a script, I am passing variables to an assembler (NASM), and I want these to be handled as strings by the assembler. That means the program being executed should receive pairs of quotes around literal text. (To ensure handling as text, in some cases I put nested quotes around a string, like "'...'", that is, double quotes around single quotes around content.) When no text is to be passed (the empty string), two quotes without content between them should be passed.
I am using Parameter Expansion, specifically the Use Default Values kind, which is described as follows in the bash manual page:
${parameter:-word}
Use Default Values. If parameter is unset or null, the expan‐ sion of word is substituted. Otherwise, the value of parameter is substituted.
This is an example of where I'm using the Use Default Values parameter expansion: https://bitbucket.org/ecm/ldebug/commits/f9b7def927cab0568e30dd9480e9d9b31f46b99f#Lsource/mak.shT58 -D_REVISIONID_SYMSNIP="${build_revision_id_symsnip:-''}"
Testing this, it seems like the double quotes around word
are allowed, but not needed.
$ bash --version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ foo=bar
$ baz=""
$ echo "${foo:-''}"
bar
$ echo "${foo:-"''"}"
bar
$ echo "${baz:-''}"
''
$ echo "${baz:-"''"}"
''
$ echo "${baz:-' '}"
' '
$ echo "${baz:-"' '"}"
' '
$ echo X"${baz:- }"Y
X Y
$ echo X"${baz:-" "}"Y
X Y
$
So, should I include the double quotes around word
or is it fine, or even preferred, without?