[xubuntu-users] dash - looping through alphabet

Steve Litt slitt at troubleshooters.com
Sat Jul 5 23:49:39 UTC 2014


On Sat, 05 Jul 2014 23:04:56 +0200
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
> 
> 

I couldn't get anything to work without putting spaces between every
letter from a to z. Would you consider a C solution? The following
prints every character between the character represented by the first
arg and the character represented by the second arg:

====================================================
#include<stdio.h>

int main(int argc, char *argv[]){
	int i;
	for(i = argv[1][0]; i <= argv[2][0]; i++)
		printf("%c\n", i);
	return 0;
}
====================================================

Here's an example session of the preceding:

====================================================
slitt at mydesq2:~$ ./a.out e g
e
f
g
slitt at mydesq2:~$
====================================================

HTH,

SteveT

Steve Litt                *  http://www.troubleshooters.com/
Troubleshooting Training  *  Human Performance





More information about the xubuntu-users mailing list