How to use find with shell variable passed as arguments?

I am a new Ubuntu Linux user and PORTEUS and I am trying to translate my old batches into bash. Therefore, I’ve a question about the right use of find with arguments because I’v many scripts with this problem. The following works fine:

find /home/abc/ -name   '* *' | while read fname . . ."  

But how to use it with arguments?

path=/home/abc/
extension=jpg
find $path -name   '*.$extension' | while read fname . . .

The above is not working for me. I’ve experimented with quotes, double quotes but I can’ find the right way.

The same problem do I have with:

num=0
for i in /home/abc/*
do 
  mv "$i" "${i%.*}$(printf '%09d' $num).${i#*.}"
 ((num++)); 
done

When replace the path with $path it doesn’t not work.I need a solution for every file () and for extension (.ext).

Does anyone has an idea?

Thanks

Peter

First problem can be sorted as follows:

path=/home/you
extension=jpg
find "$path" -name "*.$extension" | while read fname ...

Great! That works!

And with all files (*) it works too:

path=/home/you
extension=*
find “$path” -name ".$extension" | while read fname …
reads every file !
And the last Problem has a solution too:
num=0; for i in “$SOURCE”/
; do mv “$i” “${i%.}$(printf ‘%09d’ $num).${i#.}”; ((num++)); done

num=0; for i in “$SOURCE”/.".$extension"; do mv “$i” “${i%.}$(printf ‘%09d’ $num).${i#.}”; ((num++)); done

I think my problem has been, that I’ve tried to use:
extension=*.jpg
with Quotes: “$extension” or ‘$extension’
and this couldn’t work. Coming from Windows, it is not so
easy to put the quotas in the right way!

Thank You very much from Germany and
have a nice day

Peter


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki