Skip to main content
bash is not central to the question
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
edited tags
Link
terdon
  • 252.2k
  • 69
  • 480
  • 718
added 251 characters in body
Source Link
Vombat
  • 13.3k
  • 14
  • 47
  • 58

I am trying to print all directories and sub directories with a recursive function but I get only the first directory. Any help? The code is here

counter(){
    list=`ls $1`
    if [ -z "$(ls $1)" ]
    then 
        exit 0
    fi
    echo $list
    for file in $list
    do 
      if [ -d $file ]
      then 
            echo $file
            counter ./$file
      fi
    done
}

counter $1

I am trying to print all directories and sub directories with a recursive function but I get only the first directory. Any help? The code is here

I am trying to print all directories and sub directories with a recursive function but I get only the first directory. Any help?

counter(){
    list=`ls $1`
    if [ -z "$(ls $1)" ]
    then 
        exit 0
    fi
    echo $list
    for file in $list
    do 
      if [ -d $file ]
      then 
            echo $file
            counter ./$file
      fi
    done
}

counter $1
Source Link
Nasi Jofce
  • 43
  • 1
  • 2
  • 4
Loading