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

Re: bash scripting question



On Sat, Nov 02, 2002 at 10:51:00PM -0500, Neal Lippman wrote:
> 
> This works fine if I actually type out the entire alphabet list on the
> command line as above, but that's sort of a pain. So, I tried setting a
> shell variable to the alphabet string (export alpha="A,B,C,...,Z"), but
> then the command:
> 	for x in {$alpha} ; 
> 	do
> 		echo $x;
> 	done
> winds up printing the string "{A,B,C,...,Z}" rather than each letter on
> a separate line as expected.
> 

The problem here might be the way the expression is scapped:

After the for, x is substituted by $alpha, so the echo $x shows the
content of $alpha. the curly braquets might take preference over the
variable substitution, so it is used as a one item list, $alpha.

Dunno if is POSIXly correct, but it works that way.

Try using:

alpha="a b c d e" with spaces and

for x in $alpha ; do
	echo $x
done

Even trying with your idea and using the execution inverted
single-quotes (`) it is taken as a one-element list, with no comas.

HTH

-- 
Jesus Climent | Unix System Admin | Helsinki, Finland.
web: www.hispalinux.es/~data/  |  pumuki.hispalinux.es
------------------------------------------------------
Please, encrypt mail sent to me:   GnuPG ID:  86946D69
FP: BB64 2339 1CAA 7064 E429  7E18 66FC 1D7F 8694 6D69
------------------------------------------------------
Registered Linux user #66350 Debian 3.0 & Linux 2.4.20

- ... todos necesitamos creer en algo.
- Si, yo también creo... Creo... que me voy a tomar una cerveza.
		--Sor Trini (Año Mariano)

Attachment: pgp0PqFQD1JrL.pgp
Description: PGP signature


Reply to: