Context
$ bash --version GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.$ which read /usr/bin/read $ which read /usr/bin/read Can someone explain why Example 1 below works and Example 2 does not?
Example 1 - bare read works
This:
declare data data="pig,cow,horse,rattlesnake," declare -a my_array IFS=',' read -r -a my_array <<< "$data" for item in "${my_array[@]}"; do echo "$item"; done Produces:
pig cow horse rattlesnake Example 2 - /usr/bin/read fails
This produces no output:
declare data data="pig,cow,horse,rattlesnake," declare -a my_array IFS=',' /usr/bin/read -r -a my_array <<< "$data" for item in "${my_array[@]}"; do echo "$item"; done
which, trytype -a read/usr/bin/readdo on your system? (/usr/bin/read --helpor runstringson it or whatever). My Ubuntu and Arch GNU/Linux systems don't have areadexecutable because that would be pointless; shadowed by a builtin.)