bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

for i[1] in ...


From: Dan Jacobson
Subject: for i[1] in ...
Date: 26 Nov 2001 07:14:19 +0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

$ for i[1] in a b;do echo $i;done
bash: `i[1]': not a valid identifier

how non sporting.  any valid reason for not allowing this?  I mean I
wasn't trying multidimensional arrays or something.
ok, I guess i can use i1 instead

by the way, I know that exporting arrays is not allowed yet, but
anyway, any regrets here?:

$ m=(a b c);echo address@hidden
a b c
$ export m=(a b c);echo address@hidden
(a b c) b c
0bin$ export p=(a b c);echo address@hidden
(a b c)
BASH_VERSION=$'2.05.0(1)-release'

by the way
$ set -v
$ z=w
z=w
$ m=(1 v)
m=(1 v)
1 v
odd, 2 lines not one.

anyway, here's what I wipped up that was supposed to use m[1], it
works anyway now. I wonder if it is the best way to do what I'm doing.
############################## -*- Mode: sh -*- #############################
## phonecombo -- print all the letter combinations of a phone number
## Copyright       : GNU General Public License
## Author          : Dan Jacobson -- http://www.geocities.com/jidanni/
## Created On      : Jul 2001
## Last Modified By: Dan Jacobson
## Last Modified On: Mon Nov 26 07:09:27 2001
## Update Count    : 90
## Status          : worked with bash 2.05
###############################################################################
#input example: 25854780
#output: AJTJGPT0 ...[2000 lines]
#note: there are many other programs out there that probably do what
#you want instead, e.g., number2word, which does a spell check to find
#English words in there, etc.
#I just wanted to see if I could print out all those combos...
#Where I live, the phones don't have ABC... etc. anyway.
#
#note that the amount of output is 3 to the power of number of
#digits given, excluding in the total any phone digits '1' and '0'
#.e.g. phone_no 25854780 will give the same number of output lines as
#2585478, i.e. 3**7=2187

: ${1?}
case "$*" in *[^0-9]*)
     echo $0: usage: $0 phone_number \(one number only\) >&2 ;exit 44
esac
set $(echo $1|sed 's/./& /g')
for i
do
    let ++x; tab=$tab\   #tab: looks nice while debugging
    head="$head "'for m'$x' in ${letters[${phone_no['$x']}]}
'$tab'do' #newline: can then use bash line # when debugging
    middle=$middle'${m'$x'}'
    tail=$tail'; done'
done
letters=("0" "1" "A B C" "D E F" "G H I " "J K L" "M N O"
     "P R S" "T U V" "W X Y")
phone_no=(dummy $*)
eval "$head echo $middle$tail"
-- 
http://www.geocities.com/jidanni/ Tel+886-4-25854780



reply via email to

[Prev in Thread] Current Thread [Next in Thread]