Commands can also be grouped together with "
{..}".
Code:
{ commandA && commandB || loop C ; whatever ;} > file
Notice that when everything is on a single line the final bracket needs to be separated with a semicolon.
In addition, you can also use "
(..)" to run everything in a subshell, but you should really only use that when you actually
need a subshell.
PS:
$(..) is highly recommended over `..`
Edit: Actually, instead of
basename, why not simply use another parameter substitution? Doing such things in-shell is nearly always more efficient than calling an external process.
Code:
b=`basename ${k%.jpg}` #b=$(basename "${k%.jpg}") would be better
#change to:
b=${k%.jpg}
b=${b##*/}