[prev in list] [next in list] [prev in thread] [next in thread]
List: whonix-devel
Subject: [Whonix-devel] Why read exits non-zero? How to safely use bash's built-in read command?
From: Patrick Schleizer <patrick-mailinglists () whonix ! org>
Date: 2019-10-07 6:47:00
Message-ID: 31959887-de5a-08f6-f8d0-8c599411b9fa () whonix ! org
[Download RAW message or body]
I found a file that makes bash's built-in read command exit non-zero.
wget
https://raw.githubusercontent.com/Whonix/anon-connection-wizard/master/usr/share/anon-connection-wizard/advancedsettings.ico
########################################
#!/bin/bash
set -e
test -f ./advancedsettings.ico
while read -r line; do
echo "$line"
read -r first_word _ <<< "$line"
echo "$first_word"
done < "./advancedsettings.ico"
########################################
#!/bin/bash
set -e
test -f ./advancedsettings.ico
while IFS= read -r -d '' line; do
echo "$line"
IFS= read -r -d '' first_word _ <<< "$line"
echo "$first_word"
done < "./advancedsettings.ico"
########################################
bash -x ./a ; echo $?
+ set -e
+ test -f ./advancedsettings.ico
+ IFS=
+ read -r -d '' line
+ echo ''
+ IFS=
+ read -r -d '' first_word _
1
########################################
With a different - plain text - advancedsettings.ico file for testing
purposes the script would not fail. Some contents of
advancedsettings.ico is causing bash's built-in read command to exit
non-zero looks like.
Why does bash bash's built-in read command exit non-zero?
What is wrong about my usage of read
read -r first_word _ <<< "$line"
or
IFS= read -r -d '' first_word _ <<< "$line"
?
How to safely use bash's built-in read command?
Cheers,
Patrick
_______________________________________________
You are receiving this e-mail because you subscribed Whonix-devel mailing list. To unsubscribe visit \
https://www.whonix.org/cgi-bin/mailman/listinfo/whonix-devel or mail "unsubscribe" to \
Whonix-devel-unsubscribe@whonix.org.
Sie erhalten diese E-Mail, weil Sie die Whonix-devel Mailingliste aboniert haben. Zum abbestellen \
besuchen Sie https://www.whonix.org/cgi-bin/mailman/listinfo/whonix-devel oder mailen Sie "unsubscribe" \
an Whonix-devel-unsubscribe@whonix.org.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic