[Top][All Lists]

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

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

From: Peggy Russell
Subject: Re: [Help-bash] When are double quotes necessary?
Date: Thu, 24 Oct 2013 01:20:20 +0000 (UTC)
User-agent: Loom/3.14 (

> > d)
> > i=0
> > 
> > e)
> > i="0"
> d and e are identical.

The above (d, e) gets a little more interesting if you declare i with the
integer attribute. It isn't the quotes (they aren't string quotes but
expansion quotes) that are interesting, but rather the integer attribute

unset a b; declare -i a=abc ; declare -i b="abc"; declare -p a b 
declare -i z=0; declare x=2; declare -p z x; z="x + x"; echo $z $?

Quotes matter on the right-hand in a [[ expr ]]. 
With == or !=
  * No quotes, it is a pattern (globbing)
  * Quotes, it is a string
With =~ the right-hand side is a regular expression. But it is
suggested that the regular expression be an unquoted variable.

Sometimes you see:

[[ "$?" == "0" ]] vs [[ $? -eq 0 ]]

>From a bash perspective, other than "==" is a string operator and "-eq" 
a numeric operator, what is happening? 

> No, they are identical _in this context_, even if $temp expands to
> something that contains space.  Word splitting is NOT performed in
> assignment context.  Quoting has two purposes: to suppress word
> splitting, and to delineate words.  

In a Bash Programming Book, there was an example for a spinner.
Experimenting, I removed the quotes on $temp (last line) and the 
backslash (escape) wreaked havoc.

spinner="\|/-"                    ## spinner
temp=${spinner#?}                 ## remove first character from $spinner
spinner=$temp${spinner%"$temp"}   ## and add it to the end

Peggy Russell

reply via email to

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