How can I make the list of letters from A to Z and iterate through them in the shell? How can I make the list of letters from A to Z and iterate through them in the shell? unix unix

How can I make the list of letters from A to Z and iterate through them in the shell?


perl -e 'print for "a" .. "z", "A" .. "Z", 0 .. 9'


Perl

$,=" ";print +(A..Z)

or to use inside a shell:

for i in `perl -e '$,=" ";print +(A..Z)'` ; do echo $i ; done


Hope you have Ruby installed. ;)See this, plain command-line from the shell:

  1. using Ruby to iterate from A to Z and ask to print the letters:

    $ ruby -e ' "a".upto("z") {|letter| print letter}; print "\n"'
  2. iterate from A to Z and substitute the value obtained during the current iteration into a string, then print the string:

    $ ruby -e ' "a".upto("z") {|letter| puts "mkdir #{letter}"}'
    mkdir amkdir bmkdir cmkdir d...mkdir z
  3. use the output of the iteration from A to C as an argument to mkdir, in order to create 3 directories:

    $ mkdir $(ruby -e ' "a".upto("c") {|letter| puts "#{letter}"}')

    do a listing to see the results:

    $ ls -aldrwxr-xr-x  2 iuliu users  4096 2009-10-07 00:09 adrwxr-xr-x  2 iuliu users  4096 2009-10-07 00:09 bdrwxr-xr-x  2 iuliu users  4096 2009-10-07 00:09 c

Hope this helps a bit! ;)

regards,Iuliu