bug-bash
[Top][All Lists]
Advanced

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

Re: When double quote is considered when not?


From: Mart Frauenlob
Subject: Re: When double quote is considered when not?
Date: Wed, 30 Mar 2011 14:09:46 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9

On 30.03.2011 12:13, ali hagigat wrote:
The following scripts were run for /bin/bash, version 4.0.33, and then
comes their outputs. In the second example seems to have a warning:
"binary operator expected". Why the error is generated? and why there
is no error for the first example?
----------------------------------
var1="word1     word2"
echo $var1
if (test -z "\"$var1\"")   then

why run the test in a subshell?
is there any reason for the second quote pair?

echo "first"
else
echo second
fi

word1 word2
second
----------------------------------
var1="word1     word2"
echo $var1
if (test -z ""$var1"")   then

"" expands to nothing, as nothing in between opening and closing quote.
$var1 (now unqoted) expands to 'word1 word2', so the test command sees 'word2' while it expects another operator.

echo "first"
else
echo second
fi

word1 word2
./ss1: line 3: test: word1: binary operator expected
second
----------------------------------






reply via email to

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