I am facing a problem when trying to echo all the child directory of the present directory.
Now my code is like this:
for d in */; do echo "$d"; done I tried with this as well:
for d in */; do echo $d; done But every time I am getting the same error. This is:
'/test.sh: line 1: syntax error near unexpected token ` '/test.sh: line 1: `for d in */; How to solve this? Definitely I am doing some mistake. But can't figure it out.
61 Answer
The command itself works fine:
$ for d in */; do echo "$d" ; done subdir-A/ subdir-B/ However you have a hidden ' in front of the for command. Perhaps the file was copied from Windows. The easiest solution is to create a new test.sh file and copy the above command into it.