I am trying to loop through directories within a given folder and I want to skip a particular directory name. I have written this bash script to do it, but this is giving me errors. Please tell me where I am going wrong:
for f in *
do
if [ -d "$f" ]; then
if [ -d "TEST"];then
echo "skip TEST directory"
continue
fi
echo "$f"
fi
done
I want to skip TEST directory.
=as the standard equivalent to==and!as the standard equivalent to-not. See also Why is looping over find's output bad practice?. That -regex is functionally equivalent to-regex '.*/TEST.*'or its-path '*/TEST*standard equivalent. Maybe you meantfind . -name TEST -prune -o type d -print. Also rememberechocan't be used for arbitrary data. – Stéphane Chazelas Feb 24 '23 at 20:40[ -d "$f" ]also returns true on symlinks to directories whilefind's-type dexcludes them. – Stéphane Chazelas Feb 24 '23 at 20:43-execI will modify it to use exec for commands. I was just trying to provide alternatives if they were just doing something simple that a single find command could do. I will add checks for symlinks too. – Killian Fortman Feb 24 '23 at 20:49