There could be a limit on the length on the string that can be returned by a backquote commande or a limit on the length of a command (here the [tt]for i in[/tt] command).
There could be non directory entry in dirX (simple files).
Also, there could be a problem if any subdirectory has 'special' characters embedded. Special characters can be '*', ';', ' '(space) or even '\n'(newline) ... Quote every usage of your variable.
Try :
Code:
ls | while read dir; do
if [ -d "$dir" ]; then
cd "$dir"
fi
done
Or:
Code:
ls -d */. | while read dir; do
cd "$dir"
done
P.S.: I do not understand how your script (and my examples too) could work even for the second directory: once you 'cd' to the first subdirectory you are no more in dirX so you could not 'cd' into the second one. I just hope you give us a small subset of your script and that in the full script you go back to dirX at the end of the loop.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.