bug-bash
[Top][All Lists]
Advanced

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

Re: How to know the number of items of a list ?


From: Chet Ramey
Subject: Re: How to know the number of items of a list ?
Date: Thu, 1 Nov 2001 10:19:01 -0500

> I want to know how we can know the number of items of a list.

Use an array.

> I need to know this number in a loop. So I am oblige to do
> 2 loop : one to calculate this number, the other to use this
> number.
> I would like to make only one loop. 
> Is it possible ?

lsarray=( $( \ls -d ./* 2>/dev/null ) )
count=${#lsarray[@]}
for var in "${lsarray[@]}"; do
        something with $var, possibly after removing a leading `./'
done


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet)

Chet Ramey, CWRU    chet@po.CWRU.Edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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