Reputation: 61
Here is a simple script with parameter (set -e):
#!/bin/bash
set -e
echo "begin"
read -r -d '' var <<- EOF
echo "hello"
EOF
echo "${var}"
I expected no errors here, but the output is just:
begin
And "echo $?" returns 1. Why is this happening? What is wrong with read command here. If I comment out "set -e", everything works fine.
Upvotes: 3
Views: 789
Reputation: 212298
Since you've specified -d ''
(no delimiter), there is no complete input line so read is always hitting EOF and returning non-zero.
Upvotes: 3