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

Re: shell script kommands



MaD dUCK <madduck@madduck.net> wrote:
> also sprach Timeboy (on Thu, 13 Sep 2001 01:41:08PM +0200):
>> Is there a possibility to do this with a bash script?

> #!/bin/bash

> cnt=0

> while read i; do
>  var[cnt]=$i
>  cnt=`expr $cnt + 1`
> done

> echo "there are $i object(s) in array var[]."

or you could do

#!/bin/sh

eval $(
	sed -n "=;s/\([^']*\)\('*\)/'\1'\"\2\"/gp;$=" |
		sed -n ':s;N;s/^/var/;s/\n/=/p;n;$s/^/cnt=/p;bs'
)

echo "there are $cnt object(s) in array var[]."
-- 
Debian GNU/Linux 2.2 is out! ( http://www.debian.org/ )
Email:  Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt



Reply to: