Reading a delimited string into an array in Bash

前端 未结 5 1310
旧时难觅i
旧时难觅i 2020-11-29 15:17

I have a variable which contains a space-delimited string:

line=\"1 1.50 string\"

I want to split that string with space as a delimiter and

5条回答
  •  旧时难觅i
    2020-11-29 15:40

    In: arr=( $line ). The "split" comes associated with "glob".
    Wildcards (*,? and []) will be expanded to matching filenames.

    The correct solution is only slightly more complex:

    IFS=' ' read -a arr <<< "$line"
    

    No globbing problem; the split character is set in $IFS, variables quoted.

提交回复
热议问题