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

后端 未结 6 585
情深已故
情深已故 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:17

    Do like this:

    multrs="some multiple line string ...
    ...
    ..."
    
    while read -r line; do
        echo $line;
    done <<< "$mulstrs"
    

    Variable $mulstrs must be enclosed in double quotes, otherwise spaces or carriage returns will interfere with the calculation.

提交回复
热议问题