bug-bash
[Top][All Lists]
Advanced

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

exit from a piped while read does not exit program but function


From: dombek
Subject: exit from a piped while read does not exit program but function
Date: Wed, 6 Mar 2002 22:49:02 -0500

Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib -g -O2
uname output: Linux newl1.4excellence.net 2.4.9-6 #1 Thu Oct 18 09:22:43 EDT 
2001 i586 unknown
Machine Type: i586-pc-linux-gnu

Bash Version: 2.05a
Patch Level: 0
Release Status: release

Description:
        [Detailed description of the problem, suggestion, or complaint.]
        
I have a test program below that reads a file in a function and if an error 
occurs it is supposed to
exit the program.  

However, as you can see from this simple program it does not exit.

Am I missing the purpose or function of the exit statement?

Repeat-By:
        [Describe the sequence of events that causes the problem
        to occur.]

testfile.txt is the text file but any text file will do

#
#[ddombek@newl1 ddombek]$ more testme.sh 
#!/home/ddombek/bash-2.05a/bash-2.05a
#!/bin/bash

##--------------- testfile.txt ------------------
#A      B       C       D
#1      2       3       4
#5      2       7       8
#8      2       11      12
##----------- end test file ----------------

testa()
{
grep -v ^# testfile.txt | while read A B C D
        do

#       test line that works
#       ls /
#       test lne that doesn't work
        ls /12345
        error=$?
        if [ "$error" -ne 0 ]
                then
                echo "error found"
                exit
        else
                echo "error NOT found"
        fi
done
}

### The main function

#run the command
testa
echo "Error of function: $?"
echo "We shouldn't print this line if we exited the program"





reply via email to

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