[xubuntu-users] dash - looping through alphabet
Ralf Mardorf
ralf.mardorf at rocketmail.com
Sun Jul 6 05:26:34 UTC 2014
On Sat, 2014-07-05 at 19:49 -0400, Steve Litt wrote:
> I couldn't get anything to work without putting spaces between every
> letter from a to z.
Thank you,
but if this is needed, then I don't want to use a loop, but do it this
way:
case $d in
a*)
d=0;;
b*)
d=1;;
c*)
d=2;;
d*)
d=3;;
[snip]
I will do a conversion from "a_foo" to "0", "b_foo" to "1"
etc.. /dev/sda to /dev/sdz should become a number [1]. I
ignore /dev/sdAa, /dev/sdAb etc..
> Would you consider a C solution?
No, it should be a shell script and for this script I prefer dash over
bash, since the scrip should do several other operations, it should be
easy to modify it and it should be fast.
I tried another loop, but it also doesn't work.
$ cat while-dash
i=97
while [ $i != 123 ]; do
printf "\x$(printf %x $i)"
i=$((i+1))
done
printf "\n"
exit
$ bash ./while-dash
abcdefghijklmnopqrstuvwxyz
$ dash ./while-dash
\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72
\x73\x74\x75\x76\x77\x78\x79\x7a
Regards,
Ralf
[1]
# [snip]
# Transform label to hd device,partition
root_p_devdp=$(blkid -L $root_p_label | cut -f3 -d"d")
d=${root_p_devdp%%?}
i=0
for str in {a..z} ; do
# [snip] it does work without a loop, by using "case"
#case $d in
# a*)
# d=0;;
# b*)
# d=1;;
# c*)
# d=2;;
# d*)
# d=3;;
# e*)
# d=4;;
# f*)
# d=5;;
# g*)
# d=6;;
# h*)
# d=7;;
# i*)
# d=8;;
# j*)
# d=9;;
# k*)
# d=10;;
# l*)
# d=11;;
# m*)
# d=12;;
# n*)
# d=13;;
# o*)
# d=14;;
# p*)
# d=15;;
# q*)
# d=16;;
# r*)
# d=17;;
# s*)
# d=18;;
# t*)
# d=19;;
# u*)
# d=20;;
# v*)
# d=21;;
# w*)
# d=22;;
# x*)
# d=23;;
# y*)
# d=24;;
# z*)
# d=25;;
# *) printf "\n$0: can't transform label\n"; exit 2;;
#esac
p=${root_p_devdp#*?}
# [snip]
printf "\n set root='(hd$d,$p)'; set legacy_hdbias='0'"
# [snip]
More information about the xubuntu-users
mailing list