Re: how to rename multiple files
On Sun, Jan 05, 2003 at 04:13:49AM +0000, Colin Watson wrote:
> On Sat, Jan 04, 2003 at 06:58:18PM -0700, Mark Zimmerman wrote:
> > shopt -s nullglob
> > SOME=FALSE
> > MATCH=*.jpg
> > for f in $MATCH; do SOME=TRUE; break; done
> >
> > I tried [ -z $MATCH ] also but it always fails even though echo $MATCH
> > prints an empty string.
>
> You probably need to double-quote "$MATCH" like so.
>
Yes, but that's not all. Setting MATCH=*.jpg does not seem to trigger
the globbing function in bash, to my surprise. The following does
work, though:
shopt -s nullglob
MATCH=$(printf %s *.jpg)
if [ -n "$MATCH" ]; then SOME=TRUE; else SOME=FALSE; fi
By the way, I noted many solutions in other threads that should also
work fine. The reason I wanted to figure this one out is because it
relies only on shell internals. In the event that huge lists of files
are involved it may be faster.
-- Mark
Reply to: