for i in $(echo "$PATH" | sed 's/:/ /g'); do echo $i; done;
- Replace colon to space in $PATH
- Pass to for command space separated $PATH
for
command ( foo roop ) catches that strings as multiple arguments ( so not quote string )- So double quotationed string pattern does not work well because for command get in string one argument. ( e.g
"$(echo "$PATH" | sed 's/:/ /g')"
)
- So double quotationed string pattern does not work well because for command get in string one argument. ( e.g
bash-4.4$ for i in $(echo "$PATH" | sed 's/:/ /g'); do echo $i; done;
/Users/yuma/.rbenv/shims
/Users/yuma/.rbenv/bin
/Users/yuma/.rbenv/shims
/Users/yuma/.rbenv/bin
./vendor/bin
/Users/yinaura/google-cloud-sdk/bin
/usr/local/opt/openssl/bin
/Users/yuma/.pyenv/shims
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
for i in $(echo "$PATH" | sed 's/:/ /g'); do echo $i; done | head -n 1
/Users/yuma/.rbenv/shims
for i in $(echo "$PATH" | sed 's/:/ /g'); do echo $i; done | tail -n -1
/sbin
Use awk is better?
- GNU bash, version 4.4.23(1)-release (x86_64-apple-darwin17.5.0)