I am looking for a way to make a simple loop in bash on top of everything in my directory, i.e. files, directories and links, including hidden ones.
I would prefer if it can be specifically in bash, but it should be the most general. Of course, file names (and directory names) can have spaces, interrupt lines, characters. Everything except "/" and ASCII NULL (0 × 0), even with the first character. In addition, the result should exclude ".". and "..".
Here is the file generator that you have to deal with in a loop:
#!/bin/bash
mkdir -p test
cd test
touch A 1 ! "hello world" \$\"sym.dat .hidden " start with space" $'\n start with a newline'
mkdir -p ". hidden with space" $'My Personal\nDirectory'
So, my loop should look (but have to deal with the complicated things above):
for i in * ;
echo ">$i<"
done
My nearest attempt was to use an array lsand bash, but it does not work with:
IFS=$(echo -en "\n\b")
l=( $(ls -A .) )
for i in ${l[@]} ; do
echo ">$i<"
done
unset IFS
Or using bash arrays, but the ".." directory does not exclude:
IFS=$(echo -en "\n\b")
l=( [[:print:]]* .[[:print:]]* )
for i in ${l[@]} ; do
echo ">$i<"
done
unset IFS