bug-bash
[Top][All Lists]
Advanced

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

try to open file descriptor for input with 'exec' fails


From: juergen
Subject: try to open file descriptor for input with 'exec' fails
Date: Fri, 2 Nov 2007 14:24:46 +0100 (CET)

Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: linux-gnu
Compiler: gcc -I/usr/src/packages/BUILD/bash-3.2 
-L/usr/src/packages/BUILD/bash-3.2/../readline-5.2
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-suse-linux-gnu' 
-DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -O2 -march=i586 -mtune=i686 
-fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -g -D_GNU_SOURCE 
-DRECYCLES_PIDS -Wall -pipe -g -fPIE -fprofile-use
uname output: Linux starbase 2.6.22.9-0.4-default #1 SMP 2007/10/05 21:32:04 
UTC i686 i686 i386 GNU/Linux
Machine Type: i586-suse-linux-gnu

Bash Version: 3.2
Patch Level: 25
Release Status: release

Description:
In the following script i try to open a free file 
descriptor for input from a file.
The script should read lines out of a textfile, 
output goes to stdout.
This works fine till my last SUSE Linux 10.1 (sorry 
I don't know the version of the bash).
But now (opensuseLinux 10.3) the script aborts with 
following error message:

./doit: line 29: exec: 3: not found

This is the line where i try to open the file descriptor 
for input:
exec ${fd}<$inf

This error happens always with every run.
If you store the script to a file, eg. 'doit', 
then you can test it.
Call the script like: ./doit <filename> <startline> <endline>
The parameters have to be legal, because i stripped 
all cmdline parsing and errorchecking in this example.

I think it's a bug in this release of the bash.

-------------------START SCRIPT-----------------------------------------------
#!/bin/sh
#
# File: doit
#
# get lines from a file from first till last line.
# par1 = filename
# par2 = first line
# par3 = last line
# Output goes to Stdout

inf=$1                                                  # file to read from
sl=$2                                                   # start line
el=$3                                                   # end line
declare -i fd=3                                         # type is int
ifs=''
s=''                                                    # textline
i=0                                                     # line number

# find the next unused file descriptor
# range 3-9 (0-2 is STD INPUT/OUTPUT/ERROR)
while [ -t ${fd} ] && [ ${fd} -lt 9 ]; do               # fd in use
        let fd++                                        # inc fd
done

if ! [ -t ${fd} ]; then                                 # free fd found
        ifs=$IFS                                        # save IFS
        IFS=''
        i=0                                             # line number
        exec ${fd}<$inf                                 # open fd for input
        while read -rsu ${fd} s; do                     # read line
                let i++                                 # inc line number
                if [ "$i" -ge $sl ] && [ "$i" -le $el ]; then   # if in scope
                        echo "$s"                       # output line
                fi
        done
        exec ${fd}>&-                                   # close fd
        IFS=$ifs                                        # restore IFS
fi
-------------------END SCRIPT-------------------------------------------------

Repeat-By:
Always in every run.




reply via email to

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