[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Why read exits non-zero? How to safely use bash's built-in r
From: |
Patrick Schleizer |
Subject: |
[Help-bash] Why read exits non-zero? How to safely use bash's built-in read command? |
Date: |
Mon, 07 Oct 2019 06:47:00 +0000 |
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
- [Help-bash] Why read exits non-zero? How to safely use bash's built-in read command?,
Patrick Schleizer <=