Monday, February 17, 2014

Variable in for Loop Expansion

www.unixbabuforum.inI want to write a script using a for loop where one of the expansion terms is a variable. 

X=`tput lines` 

for x in {1..$X}; do 
echo $x 

This does not work. Is there a way to do this? 

I am using Solaris 10 with GNU bash, version 3.2.51(1)-release (sparc-sun-solaris2.10).

www.unixbabuforum.inTry this: 

for x in $(seq 1 $X); do echo $x; done 

for x in $( eval echo "{1..${X}} ); do echo $x; done


Post a Comment

Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM