[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] When are double quotes necessary?

From: Davide Brini
Subject: Re: [Help-bash] When are double quotes necessary?
Date: Sat, 14 Sep 2013 14:58:24 +0200

On Sat, 14 Sep 2013 12:52:47 +0000, adrelanos <address@hidden> wrote:

> Just an example.
> temp="/etc/"
> file="name"
> a)
> config_file="$temp/$file"
> b)
> config_file=""$temp"/"$file""
> c)
> config_file=$temp/$file
> d)
> i=0
> e)
> i="0"
> First, a) vs b). I like the look and feel of a) more. Is b) necessary
> and/or advised in this case?
> Actually, c) should work as well, but it is not advised, because if
> temp="/etc/ ", this could be end in a disaster just of because an
> extra space.
> For trivial cases, such as d) vs e), are quotes still recommended?

You have chosen a poor example, since word splitting (which is what double
quotes prevent) does not happen anyway upon variable assignment, so all your
examples above are exactly the same.

For the general answer, see It's
long but it's worth the read.

Also the section titled "EXPANSION" in the bash manual is worth reading;
it's not just about word splitting (which however is also covered there),
but it helps to understand what happens when bash runs a command.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]