Is it possible to replace a list "1 2 3 4 5" in "for" loop in KSH with short form 1-5?
I don't want to substitute it with while or until loop.
I don't know of a way to do exactly what you're asking for, but some versions of KSH support the for expression/compound list similar to "C":
for (( i = 1; i <= 5; i++ ))
do
echo $i
done
# end stub
This doesn't work on my Solaris 7 /bin/ksh (although Bolsky's 'The NewKornshell' says it should). It does work with ksh93 and bash. Your mileage may vary.
#!/bin/ksh
for X in 1 2 3 4 5
do
print "X is ${X}"
done
I don't think you can use the form 1-5. That's normally used for pattern matching with square brackets as in [1-5]. If you used files with the names of the numbers, this should work...
Code:
#!/bin/ksh
touch ./0 1 2 3 4 5 6 7 8 9
for X in [3-7]
do
print "X is ${X}"
done
rm [0-9]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.