On Mon, Jan 23, 2023, at 4:17 PM, Chandler wrote:
> I know it's safer to use curly braces and I've been doing that more and
> more
As an aside, unquoted ${var} is not really "safer" than unquoted
$var; they both undergo subsequent splitting and globbing. The
braces only affect how the shell determines the parameter name.
>From the man page:
${parameter}
The value of _parameter_ is substituted. The braces
are required when parameter is a positional parameter
with more than one digit, or when _parameter_ is
followed by a character which is not to be interpreted
as part of its name.
Examples:
$ set -- {a..z}
$ echo "${10}" "$10"
j a0
$ foo=1 foobar=2
$ echo "${foo}bar" "$foobar"
1bar 2
So ${var} may relieve you from having to remember how parameter
names are parsed, but it is not a substitute for quoting.
--
vq