I am using bash 3.2 on OS X.
As an exercise I have set myself the task of recursively listing files using bash builtins. I particularly don't want to use ls or find and I would prefer not to use setopt etc. The following appears to work:
Code:
g() { for k in "$1"/*; do # loop through directory
[[ -f "$k" ]] && { echo "$k"; continue; }; # echo file path
[[ -d "$k" ]] && { [[ -L "$k" ]] && { echo "$k"; continue; }; # echo symlinks but don't follow
g "$k"; }; # start over with new directory
done; }; g "/Users/neville/Desktop" # original directory
I am aware that replacing "$1"/* with "$1"/.* produces many directories such as: /Users/neville/Desktop/test dir/././././././././././.
I am also aware that the multiple directory issue can be overcome by using these terms: "$1"/.[^.]* and "$1"/..?* but I don't understand why it is necessary to totally excluded the UNIX dot files. Are the dot files acting like symlinks to directories and if so why is this not stopped by my original symlink trap? If I was happy to list all the UNIX dot and double dot files how should it be modified?