dylanaraps / pure-bash-bible

📖 A collection of pure bash alternatives to external processes.
MIT License
36.49k stars 3.28k forks source link

split string can not work with set -e #113

Closed JesseEisen closed 3 years ago

JesseEisen commented 3 years ago

https://github.com/dylanaraps/pure-bash-bible#split-a-string-on-a-delimiter

bash version

GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc.

issue I just found split function cannot work with set -e. When I open this flag, split will fail at here string part. And I can't figure out why that is not work. Can anybody explain it? Very Thanks!

WhileTrueEndWhile commented 3 years ago
$ read -d '' <<< 'Hello World'
$ echo $?
1

read returns 1 when everything is read, which is convenient when used in a while loop

$ read -d '' <<< 'Hello World' || true
$ echo $?
0

fortunately, you can simply hide the error from set -e using e.g. || true :-D

JesseEisen commented 3 years ago

aha! I see! Thanks for replying! This should be a RTFM thing 😢