Skip to main content
added 57 characters in body
Source Link
Zombo
  • 1
  • 7
  • 47
  • 65

While Gilles answer is excellent, I take issue at his main point

Always use double quotes around variable substitutions and command substitutions: "$foo", "$(foo)"

When you are starting out with a Bash-like shell that does word splitting, yes of course the safe advice is always use quotes. However word splitting is not always performed

§ Word Splitting

These commands can be run without error

foo=$bar bar=$(a command) logfile=$logdir/foo-$(date +%Y%m%d) PATH=/usr/local/bin:$PATH ./myscript case $foo in bar) echo bar ;; baz) echo baz ;; esac 

I am not encouraging users to adopt this behavior, but if someone firmly understands when word splitting occurs then they should be able to decide for themselves when to use quotes.

While Gilles answer is excellent, I take issue at his main point

Always use double quotes around variable substitutions and command substitutions: "$foo", "$(foo)"

When you are starting out with a Bash-like shell that does word splitting, yes of course the safe advice is always use quotes. However word splitting is not always performed

§ Word Splitting

These commands can be run without error

foo=$bar bar=$(a command) logfile=$logdir/foo-$(date +%Y%m%d) PATH=/usr/local/bin:$PATH ./myscript 

I am not encouraging users to adopt this behavior, but if someone firmly understands when word splitting occurs then they should be able to decide for themselves when to use quotes.

While Gilles answer is excellent, I take issue at his main point

Always use double quotes around variable substitutions and command substitutions: "$foo", "$(foo)"

When you are starting out with a Bash-like shell that does word splitting, yes of course the safe advice is always use quotes. However word splitting is not always performed

§ Word Splitting

These commands can be run without error

foo=$bar bar=$(a command) logfile=$logdir/foo-$(date +%Y%m%d) PATH=/usr/local/bin:$PATH ./myscript case $foo in bar) echo bar ;; baz) echo baz ;; esac 

I am not encouraging users to adopt this behavior, but if someone firmly understands when word splitting occurs then they should be able to decide for themselves when to use quotes.

Source Link
Zombo
  • 1
  • 7
  • 47
  • 65

While Gilles answer is excellent, I take issue at his main point

Always use double quotes around variable substitutions and command substitutions: "$foo", "$(foo)"

When you are starting out with a Bash-like shell that does word splitting, yes of course the safe advice is always use quotes. However word splitting is not always performed

§ Word Splitting

These commands can be run without error

foo=$bar bar=$(a command) logfile=$logdir/foo-$(date +%Y%m%d) PATH=/usr/local/bin:$PATH ./myscript 

I am not encouraging users to adopt this behavior, but if someone firmly understands when word splitting occurs then they should be able to decide for themselves when to use quotes.