bug-bash
[Top][All Lists]
Advanced

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

set-e and command expansion


From: Van de Bugger
Subject: set-e and command expansion
Date: Sun, 04 Feb 2024 20:27:56 +0300
User-agent: Evolution 3.48.4 (3.48.4-1.fc38)

Hi,

bash version 5.2.21(1)-release (x86_64-redhat-linux-gnu)  
Fedora Linux 38  
bash is installed from the Fedora repo, compiler I guess is gcc 13, probably
13.2 or 13.2.1

All the test scripts follow the same scheme:

#!/bin/bash  
set -e  
echo before  
COMMAND  
echo after

Let's consider few COMMAND variations and script behavior.

Case 1: false

$ cat ./test
#!/bin/bash
set -e
echo before
false
echo after

$ ./test  
before

"false" exits with status 1, so "set -e" terminates the script before "echo
after". That's expected behavior.

Case 2: var=$(false); echo $var

$ cat ./test
#!/bin/bash
set -e
echo before
var=$(false); echo $var
echo after

$ ./test  
before

The script is still terminated before "echo after" (actually, even before "echo
$var"). I didn't find in the bash manual how bash should behave in such case,
but it exits and I think this is ok.

Case 3: echo $(false)

$ cat ./test  
#!/bin/bash  
set -e  
echo before  
echo $(false)  
echo after

$ ./test  
before

after

Oops, in this case the script is NOT terminated before "echo after", but
continues to the end. I would say this is a bug, but interaction between "set -
e" and command substitution is not well defined in the bash manual. Anyway, it
looks like inconsistency: command expansion in a variable assignment terminates
the script, but the same command expansion in another command does not. What do
you think?




reply via email to

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