Question re: braces and quotes



I was reviewing the Suse/Gentoo run-crons script, and comparing it with
some elementary scripts I had written. All of a sudden, I realized that
despite reading the docs and advanced scripting manual, I really did not
have a good grasp on the concept of when to quote, enclose in a brace, etc.

This snippet crystallizes my confusion. As written, the variable
definition for LOCKFILE uses braces, but I found that it made no
difference whether or not I used braces, quotes, or any combination. I
understand that certain test contructs, such as [ -n... ] require quotes,
and if I want to manipulate a variable, braces are useful for
substitution, but could someone please explain if the first assignment of
LOCKFILE is proper, and why? For that matter, when would the assignment to
LOCKDIR have to be quoted? If there is a whitespace?

Thanks a lot!

#!/bin/sh

LOCKDIR=/var/spool/cron/lastrun
LOCKFILE=${LOCKDIR}/lock

echo "braces no quotes $LOCKFILE"

LOCKFILE="${LOCKDIR}"/lock
echo "braces quote $LOCKFILE"

LOCKFILE=$LOCKDIR/lock
echo "no braces no quote $LOCKFILE"

LOCKFILE="$LOCKDIR"/lock
echo "no braces quote $LOCKFILE"

--
Peter
.



Relevant Pages

  • Re: Question re: braces and quotes
    ... difference whether or not I used braces, quotes, or any combination. ... LOCKFILE is proper, and why? ... echo "braces no quotes $LOCKFILE" ...
    (comp.unix.shell)
  • Re: Question re: braces and quotes
    ... echo "braces no quotes $LOCKFILE" ... None of the above examples need the braces or quotes. ...
    (comp.unix.shell)
  • Re: conditional format
    ... The braces aren't the regular kind you type on the keyboard. ... Type QUOTE after the first brace, ... Select the whole Macrobutton field and press Ctrl+B to make it bold, ...
    (microsoft.public.word.newusers)
  • Re: Combining IF field and SYMBOL field fails
    ... of using {QUOTE}doesn't work either. ... real field braces.) ... Tried two different machines. ... is evaluating TRUE. ...
    (microsoft.public.word.vba.general)
  • Re: glob bug: unmatched open brace in file name
    ... % glob * ... You could probably quote just un-balanced braces on the ... syntactic rules, and then explicitly handle the delta between these ...
    (comp.lang.tcl)