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
If you need parameter expansion, then try:
eval "arr=($line)"
For example, take the following code.
line='a b "c d" "*" *'
eval "arr=($line)"
for s in "${arr[@]}"; do
echo "$s"
done
If the current directory contained the files a.txt
, b.txt
and c.txt
, then executing the code would produce the following output.
a
b
c d
*
a.txt
b.txt
c.txt