[arch-general] OT: dash - looping through alphabet
Hi! Sorry, it's OT for this list, but I didn't find an answer in the Internet. What's the syntax for a loop from "a" to "z" in dash? [rocketmouse@archlinux src]$ cat for-bash #!/bin/bash for str in {a..z} ; do printf "$str"; done printf "\n" exit [rocketmouse@archlinux src]$ cat for-dash #!/bin/dash for str in {a..z} ; do printf "$str"; done printf "\n" exit [rocketmouse@archlinux src]$ ./for-bash abcdefghijklmnopqrstuvwxyz [rocketmouse@archlinux src]$ ./for-dash {a..z} Regards, Ralf
On Sat, Jul 5, 2014 at 10:44 PM, Ralf Mardorf <ralf.mardorf@rocketmail.com> wrote:
Hi!
Sorry, it's OT for this list, but I didn't find an answer in the Internet.
What's the syntax for a loop from "a" to "z" in dash?
[rocketmouse@archlinux src]$ cat for-bash #!/bin/bash for str in {a..z} ; do printf "$str"; done printf "\n" exit
[rocketmouse@archlinux src]$ cat for-dash #!/bin/dash for str in {a..z} ; do printf "$str"; done printf "\n" exit
[rocketmouse@archlinux src]$ ./for-bash abcdefghijklmnopqrstuvwxyz [rocketmouse@archlinux src]$ ./for-dash {a..z}
Regards, Ralf
You can use echo $(seq -s '' 1 9) for number sequences, but I don't think you can do it with letters.
On Sun, Jul 6, 2014 at 8:52 PM, Karol Blazewicz <karol.blazewicz@gmail.com> wrote:
You can use
echo $(seq -s '' 1 9)
for number sequences, but I don't think you can do it with letters.
Following this line of thought, one can combine seq with printf to produce {a..z}: for i in $(seq 97 122); do printf "\x$(printf %x $i)\n" done
On Sun, 2014-07-06 at 21:16 +0800, lolilolicon wrote:
for i in $(seq 97 122); do printf "\x$(printf %x $i)\n" done
$ bash seq-dash a b [snip] x y z $ dash seq-dash \x61 \x62 [snip] \x78 \x79 \x7a $ cat seq-dash for i in $(seq 97 122); do printf "\x$(printf %x $i)\n" done :( Regards, Ralf
On Mon, Jul 7, 2014 at 12:23 AM, Ralf Mardorf <ralf.mardorf@rocketmail.com> wrote:
On Sun, 2014-07-06 at 21:16 +0800, lolilolicon wrote:
for i in $(seq 97 122); do printf "\x$(printf %x $i)\n" done
$ bash seq-dash a b [snip] x y z $ dash seq-dash \x61 \x62 [snip] \x78 \x79 \x7a
I didn't know dash's printf didn't support \x. Try octal then: for i in $(seq 97 122); do printf "\\$(printf %o $i)\n" done
$ cat seq-dash for i in $(seq 97 122); do printf "\x$(printf %x $i)\n" done
:(
Regards, Ralf
# ralf.mardorf@rocketmail.com / 2014-07-05 22:44:20 +0200:
Hi!
Sorry, it's OT for this list, but I didn't find an answer in the Internet.
What's the syntax for a loop from "a" to "z" in dash?
for c in $(printf "%b\n" $(printf "\\\0%o\n" $(seq 97 122))); do ... done for some reason, while dash(1) claims %c in printf(1) behaves just like in C, `printf "%c" 97` gives "9" (`printf("%c", 97)` in C gives "a"). this behavior is consistent across bash, dash, pdksh, posh, tcsh, zsh. -- roman
participants (4)
-
Karol Blazewicz
-
lolilolicon
-
Ralf Mardorf
-
Roman Neuhauser