Please explain the effect of redirection on this command:
Code:
~/tmp/find$ touch file file1
~/tmp/find$ find . -name f\* -exec bash -c "echo $(ls {})" \;
ls: cannot access '{}': No such file or directory
~/tmp/find$ find . -name f\* -exec bash -c "echo $(ls {} 2>&1)" \;
ls: cannot access ./file1: No such file or directory
ls: cannot access ./file: No such file or directory
In the first case, $(ls {}) is substituted before find is called, which is normal.
But in the second case, for some reason, {} is substituted with file names and then ls can not find the already found files!