I need to iterate from c to k alphabetically in shellscript, the attempt below failed, how do I do it properly?
for((i='c';i<'k';i++)) do echo $i done
I need to iterate from c to k alphabetically in shellscript, the attempt below failed, how do I do it properly?
for((i='c';i<'k';i++)) do echo $i done
This will work in bash at least:
for i in {c..k}
this one works in my shell (Bash 3.0+):
for c in {c..k}
do
echo $c
done
Given that you are not asking for bashisms specifically, here are some alternatives without them.
Simple:
for c in c d e f g h i j k; do
echo $c
done
Avoiding the need to list all the characters:
s=$(printf %d "'c")
e=$(printf %d "'k")
i=$s
while [ $i -le $e ]; do
c=$(printf \\$(printf %o $i))
echo $c
i=$((i+1))
done