Given a variable VAR
, that may contain an empty string, is it possible to make bash always interpret both
ls $VAR
ls "$VAR"
as "command that is given one argument"?
For bash, the IFS
variable allows determining how the unquoted variable expansion in the first command is interpreted, defaulting to "Split the string at newlines, tabs and spaces, and treat each one as separate argument."
Things can be made a bit more convenient by settings IFS=''
. But even then, if $VAR
expands to am empty string, it will not be treated as the empty string but as absence of an argument.
This behavior actually makes sense for other values of IFS: By default unquoted expansion is treated as "list of whitespace-separated tokens", with the empty string being the empty list.
But is there a feature, to make $VAR
and "$VAR"
truely equivalent, at least for IFS=''
?