bug-bash
[Top][All Lists]
Advanced

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

bash errexit shell option does not work in some cases.


From: Hyunho Cho
Subject: bash errexit shell option does not work in some cases.
Date: Mon, 01 Jun 2020 11:32:05 +0900

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

reply via email to

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