bug-bash
[Top][All Lists]
Advanced

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

Re: Quoting and string comparison


From: Pierre Gaston
Subject: Re: Quoting and string comparison
Date: Thu, 8 Feb 2018 17:01:21 +0200

On Thu, Feb 8, 2018 at 4:27 PM, Jaan Vajakas <address@hidden> wrote:

> So should Bash report a syntax error?
>

You do not have a syntax error, the rules for quoting inside $( ) are the
same as outside, whether you use outside quotes  "$( )" or not

So in your case you are escaping the double quotes and concatenate the
literal character " with the content of your variable, and
you end up comparing the 3 characters string <"a">  with b.

echo "$(echo \"a\")" # prints "a" the inner double quotes loose their
special meaning.





> 2018-02-08 15:24 GMT+01:00 Clark Wang <address@hidden>:
>
> > On Thu, Feb 8, 2018 at 9:05 PM, Jaan Vajakas <address@hidden>
> > wrote:
> >
> >> Hi!
> >>
> >> I noticed a weird behavior. Is it a bug?
> >>
> >> Namely, why does
> >>
> >> echo "$(for f in a b c; do if [[ \"$f\" > b ]]; then echo "$f > b"; else
> >> echo "$f <= b"; fi; done)"
> >>
> >
> > Should be:
> >
> >   echo "$(for f in a b c; do if [[ $f > b ]]; then echo "$f > b"; else
> > echo "$f <= b"; fi; done)"
> >
> >
> >> output
> >>
> >> a <= b
> >> b > b
> >> c > b
> >>
> >> ?
> >>
> >> I would have expected the same output as one of
> >> echo "$(for f in a b c; do if [[ "$f" > b ]]; then echo "$f > b"; else
> >> echo
> >> "$f <= b"; fi; done)"
> >> echo "$(for f in a b c; do if [[ '"$f"' > b ]]; then echo "$f > b"; else
> >> echo "$f <= b"; fi; done)"
> >>
> >> This happens e.g. on GNU Bash v4.4 (e.g.
> >> https://www.tutorialspoint.com/execute_bash_online.php ).
> >>
> >>
> >> Best regards,
> >> Jaan
> >>
> >
> >
>


reply via email to

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