I am writing a shell script. The number of its argument is one, and the only argument is a doubly-quoted string containing spaces like this:
$ ./test.sh "'a bcd e' 'f ghi' 'jkl mn'"
(These are required specifications and cannot be changed.)
I want to get the following output for the above input.
a bcd e
f ghi
jkl mn
However, I cannot get this result by using a simple for
loop.
In case of Bash
shell script source
#!/bin/bash
for STR in $1; do
echo $STR
done
result
$ ./test.sh "'a bcd e' 'f ghi' 'jkl mn'"
'a
bcd
e'
'f
ghi'
'jkl
mn'
In case of Zsh
shell script source
#!/bin/zsh
for STR in $1; do
echo $STR
done
result
$ ./test.sh "'a bcd e' 'f ghi' 'jkl mn'"
'a bcd e' 'f ghi' 'jkl mn'
How can I get the expected output?