Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS: -march=native -mtune=native -Wall -pipe -g3 -ggdb3 -gdwarf-4
-O2 -fno-omit-frame-pointer
uname output: Linux apgunner 5.15.11 #
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)" || {echo "foo";}
cat "$foo" || {
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
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 cl
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
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
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
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, b
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:
func()
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
proba
10 matches
Mail list logo