This produces recursive directory listings(it's intended to do other things, so there will be something else instead of echo, but it isn't important), yet it isn't very intuitive. How can I improve it?#! /bin/bashdeploy (){    for file in $(ls $1); do        if [ ! -d $2$file ]; then            echo ${2}${file}        else            deploy $2$file $2$file/        fi    done;}deploy .Output example:tmp/kdecache-z/http/ba9c27404980248a61dcdadd35f5f52395b8bddetmp/kdecache-z/http/scoreboardtmp/kdecache-z/icon-cache.kcachetmp/kdecache-z/ksycoca4tmp/kdecache-z/ksycoca4stamptmp/kdecache-z/plasma-svgelements-.customized1tmp/kdecache-z/plasma-svgelements-internal-system-colorstmp/kdecache-z/plasma_theme_.customized1.kcachetmp/kdecache-z/plasma_theme_internal-system-colors.kcachetmp/kdecache-z/tmp/kdecache-z/rctmp/kdecache-z/tmp/kdecache-z/rctmp/kdecache-z/tmp/kdecache-z/rctmp/kde-z/xauth-1000-_0tmp/ksocket-z/kdeinit4__0tmp/ksocket-z/kio_http_cache_cleanertmp/ksocket-z/klauncherhX2255.slave-sockettmp/ksocket-z/KSMserver__0tmp/pulse-PKdhtXMmr18n/nativetmp/pulse-PKdhtXMmr18n/pidtmp/qtsingleapp-homezS-8560-3e8tmp/qtsingleapp-homezS-8560-3e8-lockfiletmp/skype-2664/DbTemp./temp-KXp68f252Xx0kBMtqNdj7NFotmp/skype-2664/DbTemp./temp-NAailvY24hLGYNrZiJ99QIgHtmp/sni-qt_skype_2664-v6Xyna/icons/hicolor/24x24/apps/skype_2664_2d1ee5482260fd9cd180b32787792683.pngtmp/sni-qt_skype_2664-v6Xyna/icons/hicolor/24x24/apps/skype_2664_37e170fc54e7355d9d298917e74f9ea9.pngtmp/sni-qt_skype_2664-v6Xyna/icons/hicolor/24x24/apps/skype_2664_602c84fa0f4d61c64f770495a500279e.pngtmp/sni-qt_skype_2664-v6Xyna/icons/hicolor/24x24/apps/skype_2664_f2fc4a539a7b9553f5b35241d1154e84.pngtmp/z.socketP.S. It is working perfectly for me so I just want to make it more beautiful.
Producing recursive directory listings
beginner;bash;shell
In fairness, this task is relatively simple, and your solution is actually pretty good.Shell scripts are often just a hack to solve a specific task, and, your script is much better than many that I see that do that.There are two things to consider in your script. The first is whether it can be improved. The second is whether there's a better way.Now, about improving it. I would:remove the need for the second parametername the parameters, include the / in a different placeuse quotes around variables in specific places.reverse the if-blocks to get rid of the 'negate' condition.Consider the following:deploy () {    local dir=$1    for file in $(ls $dir/ ); do        # Fully qualified file        fqfile=$dir/$file        if [ -d $fqfile ]; then            deploy $fqfile        else            echo $fqfile        fi    done;}Introducing the fqfile allows the simplifcation of other variables too.Now, having said all that, your command could easily be solved with the find command:find . -type f -exec echo {} \;The above command will recursively find all files below ., and echo them.