bash - shell script - looping line by line - space vs line brake -
i have simple script:
$ cat $$.sh #!/bin/sh -x var="one 2 3 four" in $var ; echo $i done $
run output:
$ sh -x $$.sh + var='one 2 3 four' + in '$var' + echo 1 one + in '$var' + echo 2 two + in '$var' + echo 3 three + in '$var' + echo 4 four $
seems it's looking space , need line break instead
if you're reading multiple lines, line-by-line, while read
loop common way this:
var="one 2 3 four" while ifs='' read -r ; echo "$i" done <<< "$var"
this produces:
1 2 3 4
note in example, while loop taking input $var
variable using bash here-string redirection. redirection file or pipe.
Comments
Post a Comment