[xubuntu-users] dash - looping through alphabet

Kevin O'Gorman kogorman at gmail.com
Sun Jul 6 14:16:08 UTC 2014


How about
i=1; while [ $i -lt 27 ] ; do  echo -n $( echo abcdefghijklmnopqrstuvwxyz |
cut -c$i); i=$(( i+1 )); done; echo

For me, it echoes the alphabet on one line.
It does use  cut(1) as an external command, but at least cut is POSIX.




On Sat, Jul 5, 2014 at 2:04 PM, Ralf Mardorf <ralf.mardorf at rocketmail.com>
wrote:

> Hi,
>
> since /bin/sh on *buntu usually is dash, my request might not be OT for
> this list. Unfortunately I didn't find an answer in the
> Internet.
>
> What's the syntax for a loop from "a" to "z" in dash?
>
> $ cat for-bash
> #!/bin/bash
> for str in {a..z} ; do printf "$str"; done
> printf "\n"
> exit
>
> $ cat for-dash
> #!/bin/dash
> for str in {a..z} ; do printf "$str"; done
> printf "\n"
> exit
>
> $ ./for-bash
> abcdefghijklmnopqrstuvwxyz
> $ ./for-dash
> {a..z}
>
> Regards,
> Ralf
>
>
> --
> xubuntu-users mailing list
> xubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/xubuntu-users
>



-- 
Kevin O'Gorman

programmer, n. an organism that transmutes caffeine into software.
Please consider the environment before printing this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/xubuntu-users/attachments/20140706/661f72a8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 441 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/xubuntu-users/attachments/20140706/661f72a8/attachment.gif>


More information about the xubuntu-users mailing list