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

Re: bash scripting question



On Sat, Nov 02, 2002 at 10:05:45PM -0600, Michael Heironimus wrote:
> On Sat, Nov 02, 2002 at 10:51:00PM -0500, Neal Lippman wrote:
> > 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.
> 
> alpha="a b c d e .... z"
> for x in $alpha ; do
>         echo $x
> done
> 
> I think this should work in any Bourne-style shell....
> 
> -- 
> Michael Heironimus
> 


Doesn't work for me in bash:

$ for x in "a b c d e .... z"; do printf "$x "; done; printf "\n"
a b c d e .... z 
$

As for the original poster, an ugly solution might be with seq and tr:

$ for x in $(seq 1 5); do export y=$(printf "$x" | tr 1-5 a-e); printf
"$y "; done; printf "\n" 
a b c d e 
$
-- 

    Shaul Karl, shaulka@bezeqint.n e t



Reply to: