Walt Mankowski via plug on 26 Apr 2023 12:46:20 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
[PLUG] Splitting strings in bash |
Hi all, I've got a question about splitting strings in a bash shell script. Let's say I've got a string STR='dog cat' I'd like to split that on the space into two variables, foo and bar. I tried this echo $STR | read foo bar but it doesn't work. On the following line foo and bar are back to their original values. Then, after looking through the bash manpage for an alternative, I tried this instead read foo bar <<< $STR That DID work! So that solves my problem, but I'm still confused. Those two commands seem to me like they should be identical. Why doesn't the first one work? Walt ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug