In a Linux shell how can I process each line of a multiline string?

后端 未结 6 571
情深已故
情深已故 2021-01-31 17:24

While in a Linux shell I have a string which has the following contents:

cat
dog
bird

and I want to pass each item as an argument to another fu

6条回答
  •  遥遥无期
    2021-01-31 18:03

    if you use bash, setting IFS is all you need:

    $ x="black cat
    brown dog
    yellow bird"
    $ IFS=$'\n'
    $ for word in $x; do echo "$word"; done
    black cat
    brown dog
    yellow bird
    

提交回复
热议问题