Do the glob in two steps, and prune the .
and ..
entries manually, or with a test for "regular file". Of course the "echo" is just for testing. Add it to your list for non-trivial processing.
Edit: Silly me. Instead of actually looping twice, the list of all files (with and without dots) is just * .*
. Also, the test command [
takes its argument as a string, so we need to quote it for spaces. Revised code:
# Process non-dotfiles and dotfiles. (Only the regular files)
for f in * .*; do
if [ -f "$f" ]; then
echo $f
fi;
done
Or, use find
to do the entire job at once, including the symlinking. For example:
find . -type f \( ! -iname Makefile \) -exec ln -s \{\} newdir/\{\} \;
Or, use a combination of the two, using find -print0
pattern as suggested in your source link: that will handle the spaces and the newlines correctly, letting your script get null-separated filenames to store and further process.