Reputation: 17218
I have simple bash command that I need to put in shell:
`for f in $(ls); do echo "File -> $f"; done`
What I get is:
-bash: File: command not found
I don't understand why bash is trying to execute echo statement instead of printing it...
Upvotes: 2
Views: 3099
Reputation: 1540
Why not $(find . -mindepth 1 -maxdepth 1 -type d ! -name index -printf '%f/* ')
?
Upvotes: 2
Reputation: 9636
I used it in sh
mode, works fine. Remove the backsticks at the start and at the end of command, and it will work.
Upvotes: 1
Reputation: 77075
You should'nt be really parsing ls
for this. Do something like:
for f in *; do echo "File -> $f"; done
For directories:
for i in *; do if [ -d $i ]; then echo "File -> $i"; fi ; done
or
find . -type d -exec echo '{}' \;
Upvotes: 3
Reputation: 212198
The backticks cause the execution. The command inside the backtiks outputs a string, and the backticks execute that string as a command.
Upvotes: 3