bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about variables and for loop


From: Bob
Subject: Question about variables and for loop
Date: Sun, 19 Mar 2006 01:02:45 GMT
User-agent: Pan/0.14.90 ('Ere, he says he's not dead.)

Hi, I hope it's OK to ask questions here (the Gnu Bash FAQ seems to say
it's OK).

Values in the variable $@ can be extracted in a for loop in a way to
preserve individual strings that may have white space. For example:

        #!/bin/bash
        for x in "$@" ; do
                echo $x
        done

When called as ./doit a "b c" d
the output is

        a
        b c
        d

Is there a way to a similar for loop that processes a variable other than
$@ in the same way? For example:

        XXX='a "b c" d'
        for x in $XXX ; do
                echo $x
        done

That does not work as desired, nor does putting "$XXX" within quotes do
the trick (obviously). Is there a way?

Bob


reply via email to

[Prev in Thread] Current Thread [Next in Thread]