Find the answer to your Linux question:
Results 1 to 3 of 3
Hi to all Linux Users...I have this script: Code: #!/bin/bash read -p "give directory's name: " NAME cd $NAME count=$(ls -l | grep '\d\r\w' | wc -l) N=1 while [ ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    25

    Help With a Shell Script

    Hi to all Linux Users...I have this script:
    Code:
    #!/bin/bash
    read -p "give directory's name: " NAME
    cd $NAME
    count=$(ls -l | grep '\d\r\w' | wc -l)
    N=1
    while [ "N" -lt "$count" ]
    do 
      echo "give the name of a sub-directory"
      read NAME1
      cd $NAME1
      echo "the number of files in this sub-directory isi:"
      ls -1 | grep '\-\r\w' | wc -l
      cd ..
      N=$[N+1]
    done
    But I can't get the while loop to work.I want it so that I can find how many files has each sub-directory.Thanks in advance..

  2. #2
    Just Joined!
    Join Date
    Jul 2008
    Posts
    3
    Print count and see whether you are getting any thing in it or not.

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    25
    The real problem was that I had actually forgotten to put the $ symbol before N in the while loop condition. The correct looks like this:
    Code:
    while [ $N -lt $count ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...