Hey,
I'm new here, but I know this forum long time ago, so I decided register.
I'm making a small script for searching and doing some operations with photos, but I'm kinda stuck on this little function:
Code:
function findallformat {
prefix=""
if [ $1 = -pre ] then
shift
prefix=${1}
shift
fi
if [ -z $1 ]; then
find -name ${prefix}*
else for i in $@
do find -name ${prefix}*${1}
done
}
As you can see, I'm a newbie on Bash, and I'm just starting to program. That function should find for every file with a certain type; and you can specify a prefix using a "-pre" followed by the prefix that you want to search. The format should be "stackable", so you can use as many types that you want, without repeating the same function on the code.
Example: findallformat -pre IMG_ .JPG .CR2 #That should search files that start with "IMG_" and finishes with .JPG and .CR2.
My problem it's that, when I try to use it on the script, it says "bash: syntax error near `token' unexpected `}'"
So, can someone help me? I know it's a silly question, but I'm really stuck with it, and I tried almost everything for fixing it.
Also, what could I do for making the function nicer? Any suggestion? Tips would be appreciated.
(sorry for my bad english, I'm Brazilian)