Im learning bash and I'm trying to perform a for loop on directories, the end result im trying to achieve is if there is only one subdirectory i want to move it to another directory.
However, in its current state I have it where the for loop will get each directories subdirectory count, and I'm attempting to simply echo directories that only have 1 subdirectory, but chaining an if statement fails with "bad pattern" error. Does anyone know what im doing wrong?
for dir in ./dir/*; do output=$(ls -l $dir | grep -c ^d) && if [$output -eq 1]; then echo $dir; fi; done