Skip to Content.
Sympa Menu

baslinux - re: [BL] Bash again

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • From: Jim Varnum <jimv AT drizzle.com>
  • To: baslinux AT lists.ibiblio.org
  • Subject: re: [BL] Bash again
  • Date: Sat, 26 Apr 2003 18:46:07 -0700 (PDT)


Hi Folks...

On Sat, 26 Apr 2003 Constant Brouerius van Nidek wrote:

> Thanks for the help with bash.
> >From dos I remember that I could count the times that a loop was
> running. Could also from Lotus 123 though. Something like
>
> count=1
> .......
> count +1
> loop

In bash there are many types of "expansion". For example:

ls -l $(which busybox)

When bash executes this command it'll first execute the command in the $()
pair and apply the results to the 'which' command. The $(which busybox)
is expanded and the 'ls' command is given the full path to
busybox. This is 'command expansion'.

Another type of expansion is arithmetic expansion and is denoted by $[].
So, in a script you could do:

count=0
for x in $(ls); do
count=$[$count+1]
done
echo "There are $count files in this directory"

This will give the number of files (and directories) in the current
directory and uses both command and arithmetic expansion. BTW this is
more easily done by: ls | wc -l

Hope this helps

Jim




  • [BL] Bash again, Constant Brouerius van Nidek, 04/26/2003
    • <Possible follow-up(s)>
    • re: [BL] Bash again, Jim Varnum, 04/26/2003

Archive powered by MHonArc 2.6.24.

Top of Page