POSIX SH build loop variable with elements containing spaces

Posted by dandu on Stack Overflow See other posts from Stack Overflow or by dandu
Published on 2010-05-29T23:16:31Z Indexed on 2010/05/29 23:22 UTC
Read the original article Hit count: 274

Filed under:
|

Here's the code I need:

#!/bin/sh

x1="a1 a2"
x2="b1 b2"

list=SOMETHING

for x in "$list"
do
    echo $x
done

And the output I want:

a1 a2
b1 b2

The question is: what should SOMETHING be? I want $list to behave just as $@ does.

Notes: I can't use $IFS and I can't eval the entire loop.

© Stack Overflow or respective owner

Related posts about bash

Related posts about sh