Re: Interesting bug

2022-02-13 Thread Chet Ramey
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

Re: Interesting bug

2022-02-13 Thread Chet Ramey
On 2/12/22 5:20 PM, David Hobach wrote: Thanks a lot for the detailed explanations, much appreciated! So essentially it's no bug - just a rather uncommon choice of keywords. I still don't agree with that choice since it can be abused to somewhat hide code in pull requests to less experienced

Re: Interesting bug

2022-02-12 Thread David Hobach
Thanks a lot for the detailed explanations, much appreciated! So essentially it's no bug - just a rather uncommon choice of keywords. I still don't agree with that choice since it can be abused to somewhat hide code in pull requests to less experienced maintainers, but oh well... there's

Re: Interesting bug

2022-02-12 Thread Ilkka Virta
On Sat, Feb 12, 2022 at 8:25 PM David Hobach wrote: > 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). > Let's see if I get this right. Removing the irrelevant parts, your code is pretty much this:

Re: Interesting bug

2022-02-12 Thread Martin Schulte
Hi David! > A syntax error would be nice instead. I see - also from you second answer - that you have some fundamental misunderstandings about shell programming: - Your code will, in case the testCode fails, try execute a program called {echo. This is certainly not a good name for a program,

Re: Interesting bug

2022-02-12 Thread Andreas Schwab
On Feb 12 2022, David Hobach wrote: > 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

Re: Interesting bug

2022-02-12 Thread David Hobach
P.S.: Also, if you remove the case/esac from the original example, it'll result in a syntax error. So why can the case/esac be used to ignore the syntax error? smime.p7s Description: S/MIME Cryptographic Signature

Re: Interesting bug

2022-02-12 Thread David Hobach
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

Re: Interesting bug

2022-02-12 Thread Léa Gris
On 12/02/2022 at 12:23, David Hobach wrote: function tfunc {   local foo=   foo="$(testCode)" || {echo "foo";} ^ Missing space after opening brace Because the code block is missing a space after the opening brace; the opening brace is ignored, but the following

Re: Interesting bug

2022-02-12 Thread Martin Schulte
Hello David! > 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";} Best regards Martin

Interesting bug

2022-02-12 Thread David Hobach
Dear all, I think I found a rather interesting bug: ``` #!/bin/bash function badCode { echo "bad code executed" } function testCode { #pick some existing file, nonexisting works too though echo "/etc/passwd" } function tfunc { local foo= foo="$(testCode)"