Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16331

bash errexit shell option does not work in some cases.

From Hyunho Cho<mug896@naver.com>
Newsgroups gnu.bash.bug
Subject bash errexit shell option does not work in some cases.
Date 2020-06-01 11:32 +0900
Message-ID <mailman.869.1590978736.2541.bug-bash@gnu.org> (permalink)
References <3f403934d6b5d23ca58afc5146416c7@cweb006.nm.nfra.io>

Show all headers | View raw


GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
 Operating System: Ubuntu 20.04 LTS
 Kernel: Linux 5.4.0-33-generic
 Architecture: x86-64


bash errexit shell option does not work in some cases.
after execution a command, exitcode is set to "1" but shell script does not exited.


#################   WORK CASE   #######################

#!/bin/bash -e                   # errexit option

cat < not_exist.txt             # not exist file

echo end ....

######  result  ######

$ ./test.sh                          # work as expected
./test.sh: line 3: not_exist.txt: No such file or directory


###################   NOT WORK  CASES  #######################

#!/bin/bash -e

{ cat ;} < not_exist.txt   

echo "exitcode : $?"
echo end ....

######  result  ######

$ ./test.sh         
exitcode : 1           # exitcode is set to "1" 
./test.sh: line 3: not_exist.txt: No such file or directory
end ....                  # but test.sh does not exited

--------------------------------------------------------------------------------------

#!/bin/bash -e           

while read -r line; do 
    echo "$line"
done < not_exist.txt  

echo "exitcode : $?"
echo end.....

######  result  ######

$ ./test.sh
./test.sh: line 5: not_exist.txt: No such file or directory
exitcode : 1        # exitcode is set to "1"
end.....                # but does not exited

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

bash errexit shell option does not work in some cases. Hyunho Cho<mug896@naver.com> - 2020-06-01 11:32 +0900

csiph-web