Jerry, On Thursday 05 May 2005 05:30, Jerry Feldman wrote:
#!/bin/bash for i in $(ls -p) do case $i in */) cd $i; pth=$PWD; for sname in $(ls) do case $sname in *script*) echo "$sname found in $pth";; esac done cd ..;; esac done
Two (and a half) things: 1) Quote all references to the variables $i, $pth, $PWD and $sname. 2) Add this line before the for loop: IFS=$'\n' The half thing is to use better (more connotative and less abbreviated) variable names, not to smash so much stuff onto single lines and to avail yourself of the full range of BASH facilities. Here's the script I used to verify my solution to your question: -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- #!/bin/bash IFS=$'\n' for dirEnt in $(ls -p) do case $dirEnt in */) cd "$dirEnt" dir="$PWD" for sName in $(ls); do if [[ "$sName" = *script* ]]; then echo "script \"$sName\" found in $dir" fi # case "$sName" in # *script*) # echo "script \"$sName\" found in $dir" # ;; # esac done cd .. ;; *) echo "Non-dir: \"$dirEnt\"" ;; esac done -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==- Lastly, I'll point out that using the "-p" option of "ls" to distinguish the kind of file system entity you're dealing with is probably not the best choice. You're only getting away with it in this script because in most contexts (beware rsync) a directory name means / refers to is the same thing with or without the trailing slash. Other things (the @ sign used to signify a symbolic link or the * used to mark executable files, e.g.) will probably impair any attempt to actually reference the file system entity in question. Check out the "test" (a.k.a. "[") shell built-in for the preferred way to make file type- and mode-specific determinations in your scripts ("help test"). Randall Schulz