Avoiding quoting is desirable when we want shell to think "oh, these are all separate elements, not one whole!". Such thing can be quite useful with arrays.
bash-4.3$ var="one two three"
bash-4.3$ arr=( $var )
bash-4.3$ for i in "${arr[@]}"; do echo "$i"; done
one
two
three
In particular , this is useful when you are generating an array as in example above. I've personally used such approach when enumerating actual addresses of the Ubuntu workspaces ( exact terminology is viewports, and they use format of coordinates like X,y , but that's whole lot different story ).
Another approach is when you're giving the variable to another command that needs to process them as separate items. Compare:
bash-4.3$ bash -c 'for item; do echo $item; done' sh "$var"
one two three
bash-4.3$ bash -c 'for item; do echo $item; done' sh $var
one
two
three
To address what has been mentioned in the comments, these examples aren't meant to be used with "unexpected input", and rather for controlled environment. In addition, set noglob
can be used if globing is to be avoided, but again - if you are generating an array for certain combination of strings such as numeric values of desktop viewports, there's no danger from glog
at all. If you're dealing with actual user input, then quotes are to be used, and this is not what was the topic of this question.
verbose=; [[ some_condition ]] && verbose=-v; ...; some_program $verbose some_args
– Chris Davies Nov 18 '16 at 10:29if [[ "${nr}" -lt 1 ]]
. the answer given by you contains some cases which i should treat differently i guess – magor Nov 18 '16 at 10:41