[Top][All Lists]

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

Re: Interesting bug

From: Chet Ramey
Subject: Re: Interesting bug
Date: Sun, 13 Feb 2022 14:31:16 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.0

On 2/12/22 1:24 PM, David Hobach wrote:
I guess 99% of programmers would either expect "Finished" to be printed or some syntax error.

Well, 99% of shell programmers will (hopefully ;-) ) put a blank between "{" and "echo" in the line

foo="$(testCode)" || {echo "foo";}

Yes, the interesting part is that depending on which space you accidentally forget, you'll either get the expected "Finished" or "bad code executed".
foo="$(testCode)" || {echo "foo"; } # --> bad code
foo="$(testCode)" || { echo "foo";} # --> Finished

I guess it closes the function and {echo is interpreted as string or so, but that is probably not all (testCode is e.g. never executed).

It's not executed because it's part of a function that's never called.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

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