Reputation: 6504
In my home directory, I am having a script named blabs
and I am passing a file as argument to this bash script like:
./blabs \home\blabs\someFileName
And this will give the results and everything is working fine.
Now I want to automate this task.I have 1000 files in a directory named 2016_10_1
located in home directory.So I want to pass each file as argument to the script.
I wrote a small snippet but it is not working properly.Can anyone help me with this
for i in (find /home/blabs/2016_10_1/ -type f);do "./blabs /home/blabs/2016_10_1/$i";done
Error Log:
-bash: syntax error near unexpected token `('
Upvotes: 0
Views: 72
Reputation: 8393
Yes, as Oliv suggests, you may quick fix this by adding a $
:
for i in $(find . -type f); do echo "THIS $i"; done
Upvotes: 1
Reputation: 853
Find has a built in execute on all found items. So this command will do what you are looking for.
find /home/blabs/2016_10_1/ -type f -exec /path/to/blabs {} \;
Upvotes: 2
Reputation: 85865
See ParsingLs, why you should NOT parse output of
find
orls
in a for loop.
You use a process substitution syntax(<()
) like below,
#!/bin/bash
while IFS= read -r file
do
/path/to/blabs "$file"
done< <(find /home/blabs/2016_10_1/ -type f)
The output of find
is fed one line at time to the while loop, and the script ./blabs
executed on it.
Upvotes: 1