lwv27@CAS.BITNET (12/19/90)
I am attempting to turn a ksh variable into an array and then back into the variable after manipulation. Here is what I have: ==== Cut here ==== #! /bin/ksh # Now convert this into an array IFS=":" ; export IFS set -A tbl $PATH size=${#tbl[*]} i=0 while [ $i -lt $size ] ; do echo "Table element $i is ${tbl[$i]}" ((i+=1)) done lst="${tbl[*]}" lst2="${tbl[@]}" echo $lst echo $lst2 exit 0 === Cut Here === The problem is that I cannot figure out how to get the colons back into the PATH. What I want to be able to do is to null out entries all together, so they are not even present. What I would REALLY like to do is to have something like an array 'shift' type mechanism I think! -- Larry W. Virden UUCP: osu-cis!chemabs!lwv27 Same Mbox: BITNET: lwv27@cas INET: lwv27%cas.BITNET@CUNYVM.CUNY.Edu Personal: 674 Falls Place, Reynoldsburg,OH 43068-1614 America Online: lvirden
mvadh@cbnews.att.com (andrew.d.hay) (12/19/90)
In article <9012190340.AA20465@lilac.berkeley.edu>, lwv27@CAS.BITNET writes: > I am attempting to turn a ksh variable into an array and then back > into the variable after manipulation. Here is what I have: > [] > > The problem is that I cannot figure out how to get the colons back into > the PATH. What I want to be able to do is to null out entries all together, > so they are not even present. What I would REALLY like to do is to > have something like an array 'shift' type mechanism I think! here's what i do with TERMCAP: set -A TERMCAP $(infocmp -C) typeset -i BIT=1 while [[ BIT -le ${#TERMCAP[@]} ]] do TERMCAP="${TERMCAP%:? }${TERMCAP[$BIT]} " (( BIT += 1 )) done set -A TERMCAP "$TERMCAP" export TERMCAP hope this helps... -- Andrew Hay +------------------------------------------------------+ Ragged Individualist | You just have _N_O idea! It's the difference | AT&T-BL Ward Hill MA | between _S_H_O_O_T_I_N_G a bullet and _T_H_R_O_W_I_N_G it! | a.d.hay@att.com +------------------------------------------------------+
davidsen@sixhub.UUCP (Wm E. Davidsen Jr) (12/20/90)
Well, when you have the final array of values... LIM=${A[*]} n=1 PATH=${A[0]} while [ $n -lt $LIM ]; do PATH=$PATH:${A[$n]} let n=n+1 done - or - PATH=$(echo ${A[*]} | tr " " ":") which is a lot simpler, but probably slower because it runs a process instead of all being in ksh. Let me know if one of these helps. -- bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen) sysop *IX BBS and Public Access UNIX moderator of comp.binaries.ibm.pc and 80386 mailing list "Stupidity, like virtue, is its own reward" -me