I don't know if it's another behaviour of the same issue, but today, I noticed that "while read" results aren't given out of the loop in bash 5.0.18.
Here my example:
>cat hga.mailsend.table
# This is a comment line
# Now an address line:
donald.duck@duckburg.demickey.mouse@nowhere.com>cat hga.sh
#!/bin/bash
echo "My bash version is ${BASH_VERSION}"
emma="will it be changed ?"
hugo="initial value before loop"
anna="initial value before loop"
cat hga.mailsend.table | while read myrec ; do
echo "myrec: $myrec"
#
emma=$myrec
echo "inside loop: emma=$emma"
#
hugo="$hugo + $myrec"
echo "inside loop: hugo=[$hugo]"
#
anna=$(echo "$hugo + $myrec")
echo "inside loop: anna=[$anna]"
done
#
echo "loopend: emma=[$emma]"
echo "loopend: hugo=[$hugo]"
echo "loopend: anna=[$anna]"
The result is:
>./hga.sh
My bash version is 5.0.18(1)-release
myrec: # This is a comment line
inside loop: emma=# This is a comment line
inside loop: hugo=[initial value before loop + # This is a comment line]
inside loop: anna=[initial value before loop + # This is a comment line + # This is a comment line]
myrec: # Now an address line:
inside loop: emma=# Now an address line:
inside loop: hugo=[initial value before loop + # This is a comment line + # Now an address line:]
inside loop: anna=[initial value before loop + # This is a comment line + # Now an address line: + # Now an address line:]
myrec:
donald.duck@duckburg.deinside loop: emma=
donald.duck@duckburg.deinside loop: hugo=[initial value before loop + # This is a comment line + # Now an address line: +
donald.duck@duckburg.de]
inside loop: anna=[initial value before loop + # This is a comment line + # Now an address line: +
donald.duck@duckburg.de +
donald.duck@duckburg.de]
myrec:
mickey.mouse@nowhere.cominside loop: emma=
mickey.mouse@nowhere.cominside loop: hugo=[initial value before loop + # This is a comment line + # Now an address line: +
donald.duck@duckburg.de +
mickey.mouse@nowhere.com]
inside loop: anna=[initial value before loop + # This is a comment line + # Now an address line: +
donald.duck@duckburg.de +
mickey.mouse@nowhere.com +
mickey.mouse@nowhere.com]
loopend: emma=[will it be changed ?]
loopend: hugo=[initial value before loop]
loopend: anna=[initial value before loop]
So, the read loop works correct, no hangup, but the values set in the loop are reset after "done".
If I change the while-pipe to "for myrec in $(cat hga.mailsend.table); do" , I get the variable contents outside of the loop, but as "for" split by words, it doesn't make sense.
It seems not related to file I/O, for example:
cat hga.endless.sh
#!/bin/bash
ctr=0
while hugo="init" ; do
echo "before: $hugo"
hugo="exit"
echo "after: $hugo"
let ctr=ctr+1
[[ $ctr -gt 10 ]] && exit
done
echo "The end is near..."
Result :
./hga.endless.sh
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
before: init
after: exit
...aborted by ctrl-c...
------------------------------
Achim Haag
------------------------------
Original Message:
Sent: Fri April 23, 2021 02:06 AM
From: SANGAMESH MALLAYYA
Subject: Issue with Bash read builtin in latest release
It seems bash-5.1 has changed the ways FIFOs are implemented, hence the patch which is causing this issue is no more required.
We will be to updating bash to 5.1 which fixes this issue and let you know once it's available on AIX Toolbox.
------------------------------
SANGAMESH
------------------------------
Original Message:
Sent: Wed April 21, 2021 09:22 AM
From: Mike Whitton
Subject: Issue with Bash read builtin in latest release
Thanks for taking the time to look into this.
I have also been communicating with one of the maintainers of bash and he feels that the way patch 17 was implemented in the IBM version is causing the problem, he feels that the FIFO's are not being reaped properly after being written to.
btw, I was able to recompile the mainline bash binaries with all of the patches upto 18 applied and it works on the same AIX server without issue. So I do believe this issue exists with the distribution of bash released by IBM...
Thanks
------------------------------
Mike Whitton
Original Message:
Sent: Wed April 21, 2021 03:29 AM
From: Achim Haag
Subject: Issue with Bash read builtin in latest release
Strange, running your script, it doesn't end, it stands on the last read:
<root@t0201:/home/00000217/testdir>./testhg2.sh
SGLIST=("testfile1" "testfile1" "testfile1" "testfile1")
+ SGLIST=("testfile1" "testfile1" "testfile1" "testfile1")
for sg in ${SGLIST[@]}
do
while read line
do
echo "$line"
done < <(ls -al ./ 2>&1)
done
+ for sg in ${SGLIST[@]}
+ read line
++ ls -al ./
+ echo 'total 32'
total 32
+ read line
+ echo 'drwxr-xr-x 2 root system 256 Apr 21 09:12 .'
drwxr-xr-x 2 root system 256 Apr 21 09:12 .
+ read line
+ echo 'drwxr-xr-x 7 00000217 staff 4096 Apr 21 09:04 ..'
drwxr-xr-x 7 00000217 staff 4096 Apr 21 09:04 ..
+ read line
+ echo '-rwxr-xr-x 1 root system 179 Apr 21 09:15 testhg2.sh'
-rwxr-xr-x 1 root system 179 Apr 21 09:15 testhg2.sh
+ read line
+ echo '-rwxr-xr-x 1 root system 378 Apr 21 09:26 testhga.sh'
-rwxr-xr-x 1 root system 378 Apr 21 09:26 testhga.sh
+ read line
+ echo '-rwxr-xr-x 1 root system 381 Apr 21 09:12 testhgb.sh'
-rwxr-xr-x 1 root system 381 Apr 21 09:12 testhgb.sh
+ read line
Now I modified it slightly and it works (run it 50 times):
<root@t0201:/home/00000217/testdir>cat testhga.sh
!/bin/bash
echo "bash version: ${BASH_VERSINFO}"
rpm -qa |grep bash
SGLIST=("testfile1" "testfile1" "testfile1" "testfile1")
i=0
for sg in ${SGLIST[@]}
do
let i=i+1
echo "Loop $i"
j=0
while read line
do
let j=j+1
echo "Loop $i MYLINE: $line"
done < <(ls -al ./ 2>&1)
done
<root@t0201:/home/00000217/testdir>kkk
<root@t0201:/home/00000217/testdir>./testhga.sh
./testhga.sh: line 1: !/bin/bash: No such file or directory
bash version: 5
bash-5.0.18-1.ppc
Loop 1
Loop 1 MYLINE: total 32
Loop 1 MYLINE: drwxr-xr-x 2 root system 256 Apr 21 09:12 .
Loop 1 MYLINE: drwxr-xr-x 7 00000217 staff 4096 Apr 21 09:04 ..
Loop 1 MYLINE: -rwxr-xr-x 1 root system 179 Apr 21 09:15 testhg2.sh
Loop 1 MYLINE: -rwxr-xr-x 1 root system 378 Apr 21 09:26 testhga.sh
Loop 1 MYLINE: -rwxr-xr-x 1 root system 381 Apr 21 09:12 testhgb.sh
Loop 2
Loop 2 MYLINE: total 32
Loop 2 MYLINE: drwxr-xr-x 2 root system 256 Apr 21 09:12 .
Loop 2 MYLINE: drwxr-xr-x 7 00000217 staff 4096 Apr 21 09:04 ..
Loop 2 MYLINE: -rwxr-xr-x 1 root system 179 Apr 21 09:15 testhg2.sh
Loop 2 MYLINE: -rwxr-xr-x 1 root system 378 Apr 21 09:26 testhga.sh
Loop 2 MYLINE: -rwxr-xr-x 1 root system 381 Apr 21 09:12 testhgb.sh
Loop 3
Loop 3 MYLINE: total 32
Loop 3 MYLINE: drwxr-xr-x 2 root system 256 Apr 21 09:12 .
Loop 3 MYLINE: drwxr-xr-x 7 00000217 staff 4096 Apr 21 09:04 ..
Loop 3 MYLINE: -rwxr-xr-x 1 root system 179 Apr 21 09:15 testhg2.sh
Loop 3 MYLINE: -rwxr-xr-x 1 root system 378 Apr 21 09:26 testhga.sh
Loop 3 MYLINE: -rwxr-xr-x 1 root system 381 Apr 21 09:12 testhgb.sh
Loop 4
Loop 4 MYLINE: total 32
Loop 4 MYLINE: drwxr-xr-x 2 root system 256 Apr 21 09:12 .
Loop 4 MYLINE: drwxr-xr-x 7 00000217 staff 4096 Apr 21 09:04 ..
Loop 4 MYLINE: -rwxr-xr-x 1 root system 179 Apr 21 09:15 testhg2.sh
Loop 4 MYLINE: -rwxr-xr-x 1 root system 378 Apr 21 09:26 testhga.sh
Loop 4 MYLINE: -rwxr-xr-x 1 root system 381 Apr 21 09:12 testhgb.sh
<root@t0201:/home/00000217/testdir>
------------------------------
Achim Haag
Original Message:
Sent: Tue April 20, 2021 12:57 PM
From: Mike Whitton
Subject: Issue with Bash read builtin in latest release
I downloaded the official GNU release, patched it to version 5.0.18, the same release IBM is distributing, and it is working fine. The GCC compilers and GNU Make were used to build this package.
There is possibly something wrong with the version that is being distributed on the IBM AIX Linux Toolbox website.
Thanks
------------------------------
Mike Whitton