Reputation: 37
Trying to write a bash script to process a bunch of sub-directories in the directory that its run in. I need to cd into each directory, compile some code, and run the executable. The problem is that when I iterate through the files in my current directory it includes the "." and ".." and I don't want those to be iterated on. What's the easiest way around this?
Current code I'm working with:
for file in .* *
do
echo "entering $file"
cd $file
done
Output looks like:
entering .
entering ..
By the time it looks for other files in my local directory its up too many directories to be useful. How do I remove . and .. from the list that I iterate through?
Apologies if this is a dumb question - very new to bash scripting.
Thanks in advance.
Upvotes: 1
Views: 38
Reputation: 177785
shopt -s dotglob
will make *
include dotfiles but not .
and ..
.
Upvotes: 3