Skip to main content
added 7 characters in body
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324

Don't quote when you want an empty variable to disappear (as distinct from remaining as an empty string):

verbose= [[ some_condition ]] && verbose=-v # ...later... some_program $verbose some_args 

Don't quote when your variable contains whitespace separated arguments and you want the shell to treat them as separate words

exclude_file= [[ -s excludelist.txt ]] && exclude_file='--exclude excludelist.txt' # ...later... rsync -avP $exclude /path/to/source/ remote:target 

The general approach is always use double-quote unless you know why you don't want them.The general approach is always to use double-quotes unless you know why you don't want them.

Don't quote when you want an empty variable to disappear (as distinct from remaining as an empty string):

verbose= [[ some_condition ]] && verbose=-v # ...later... some_program $verbose some_args 

Don't quote when your variable contains whitespace separated arguments and you want the shell to treat them as separate words

exclude_file= [[ -s excludelist.txt ]] && exclude_file='--exclude excludelist.txt' # ...later... rsync -avP $exclude /path/to/source/ remote:target 

The general approach is always use double-quote unless you know why you don't want them.

Don't quote when you want an empty variable to disappear (as distinct from remaining as an empty string):

verbose= [[ some_condition ]] && verbose=-v # ...later... some_program $verbose some_args 

Don't quote when your variable contains whitespace separated arguments and you want the shell to treat them as separate words

exclude_file= [[ -s excludelist.txt ]] && exclude_file='--exclude excludelist.txt' # ...later... rsync -avP $exclude /path/to/source/ remote:target 

The general approach is always to use double-quotes unless you know why you don't want them.

Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324

Don't quote when you want an empty variable to disappear (as distinct from remaining as an empty string):

verbose= [[ some_condition ]] && verbose=-v # ...later... some_program $verbose some_args 

Don't quote when your variable contains whitespace separated arguments and you want the shell to treat them as separate words

exclude_file= [[ -s excludelist.txt ]] && exclude_file='--exclude excludelist.txt' # ...later... rsync -avP $exclude /path/to/source/ remote:target 

The general approach is always use double-quote unless you know why you don't want them.