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...
The backticks cause the execution. The command inside the backtiks outputs a string, and the backticks execute that string as a command.
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 '{}' \;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With