f



BASH Command Query?!?!

I am trying to batch process a bunch of camera photo files and have a
working command but I'm trying to refine it.

I have a series of photo files with the following syntax:
crw_1270.crw
crw_1271.crw

I have written a script to convert to a low res jpeg: 
for i in *.crw; do dcraw -w -c $i | cjpeg > $i.lo.jpg; echo $i; done

crw_1270.crw
crw_1270.crw.lo.jpg
crw_1271.crw
crw_1271.crw.lo.jpg

But, I'm trying to shorten the resulting output file name a bit.  I've
tried the following command (watch for the line wrap):

for i in *.crw; j=`echo $i | cut -d "." -f 1`; do dcraw -w -c $i |
cjpeg > $j.lo.jpg; echo $i; done

To attempt to get this result ...

crw_1270.crw
crw_1270.lo.jpg
crw_1271.crw
crw_1271.lo.jpg

But I get this error message!

-bash: syntax error near unexpected token `j=`echo $i | cut -d "." -f
1`'

Can anyone suggest a simple solution or point out what I'm doing
wrong?!?!  This is really just a "nice to have" but I haven't run into
this problem in a shell script, only in this extended command method.

Thanks in advance!  
--
------------------------------------------------
         http://www3.sympatico.ca/dmitton
  SPAM Reduction: Remove "x." from my domain.
------------------------------------------------
0
Doug
5/3/2005 1:03:09 PM
comp.os.linux.misc 33584 articles. 0 followers. amosa69 (78) is leader. Post Follow

6 Replies
505 Views

Similar Articles

[PageSpeed] 59

On 2005-05-03, Doug Mitton <doug_mitton@hotmail.x.com> wrote:
> I have written a script to convert to a low res jpeg: 
> for i in *.crw; do dcraw -w -c $i | cjpeg > $i.lo.jpg; echo $i; done


Try with 

<snipped> $i | cjpeg > `basename $i .crw`.lo.jpg; <snipped>

Note the backquotes (`).

Davide

-- 
Windows NT encountered the following error: The operation completed
successfully. 
   -- From a Slashdot.org post
0
5/3/2005 12:23:48 PM
Doug Mitton <doug_mitton@hotmail.x.com> wrote:

> for i in *.crw; j=`echo $i | cut -d "." -f 1`; do dcraw -w -c $i |
> cjpeg > $j.lo.jpg; echo $i; done

> But I get this error message!

> -bash: syntax error near unexpected token `j=`echo $i | cut -d "." -f
> 1`'

The syntax of `for' is:  for x in <list>; do <commands>; done

The `do' must come IMMEDIATELY after the first ; or your command line
won't parse. That's why the token `j=`echo...' is unexpected: bash is
expecting the `do' in that place. Put it there.


-- 
No animal was harmed in the composition of this message.

0
foth (74)
5/3/2005 1:24:32 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Davide Bianchi wrote:
> On 2005-05-03, Doug Mitton <doug_mitton@hotmail.x.com> wrote:
> 
>>I have written a script to convert to a low res jpeg: 
>>for i in *.crw; do dcraw -w -c $i | cjpeg > $i.lo.jpg; echo $i; done
> 
> 
> 
> Try with 
> 
> <snipped> $i | cjpeg > `basename $i .crw`.lo.jpg; <snipped>

Or even

  for i in *.crw ; \
  do dcraw -w -c $i | cjpeg >${i%%.crw}.lo.jpg ; \
  echo $i ; \
  done



- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCd9JpagVFX4UWr64RAt8YAKD1bDKv+RvZC+td5lRZvUK7uuYZRACg5vcT
IPR2fPthk9uMI1BSQvmXkE0=
=tDOo
-----END PGP SIGNATURE-----
0
Lew.Pitcher (533)
5/3/2005 7:35:05 PM
On Tue, 03 May 2005 at 13:03 GMT, Doug Mitton wrote:
> I am trying to batch process a bunch of camera photo files and have a
> working command but I'm trying to refine it.
> 
> I have a series of photo files with the following syntax:
> crw_1270.crw
> crw_1271.crw
> 
> I have written a script to convert to a low res jpeg: 
> for i in *.crw; do dcraw -w -c $i | cjpeg > $i.lo.jpg; echo $i; done
> 
> crw_1270.crw
> crw_1270.crw.lo.jpg
> crw_1271.crw
> crw_1271.crw.lo.jpg
> 
> But, I'm trying to shorten the resulting output file name a bit.  I've
> tried the following command (watch for the line wrap):
> 
> for i in *.crw; j=`echo $i | cut -d "." -f 1`; do dcraw -w -c $i |
> cjpeg > $j.lo.jpg; echo $i; done
> 
> To attempt to get this result ...
> 
> crw_1270.crw
> crw_1270.lo.jpg
> crw_1271.crw
> crw_1271.lo.jpg
> 
> But I get this error message!
> 
> -bash: syntax error near unexpected token `j=`echo $i | cut -d "." -f
> 1`'
> 
> Can anyone suggest a simple solution or point out what I'm doing
> wrong?!?!  This is really just a "nice to have" but I haven't run into
> this problem in a shell script, only in this extended command method.

   First, format your script so that it can be more easily understood:

for i in *.crw
 j=`echo $i | cut -d "." -f 1`
do
   dcraw -w -c $i | cjpeg > $j.lo.jpg
   echo $i
done

   Once you have done that, the error is obvious: 'do' is in the wrong place.

   Also, there is no need to use cut:

j=${i%%.*}

-- 
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/ssr.html>
0
cfajohnson (1827)
5/3/2005 9:23:13 PM
Doug Mitton <doug_mitton@hotmail.x.com> wrote:

>I am trying to batch process a bunch of camera photo files and have a
>working command but I'm trying to refine it.
>
>I have a series of photo files with the following syntax:
>crw_1270.crw
>crw_1271.crw
>
>I have written a script to convert to a low res jpeg: 
>for i in *.crw; do dcraw -w -c $i | cjpeg > $i.lo.jpg; echo $i; done
>
>crw_1270.crw
>crw_1270.crw.lo.jpg
>crw_1271.crw
>crw_1271.crw.lo.jpg
>
>But, I'm trying to shorten the resulting output file name a bit.  I've
>tried the following command (watch for the line wrap):
>
>for i in *.crw; j=`echo $i | cut -d "." -f 1`; do dcraw -w -c $i |
>cjpeg > $j.lo.jpg; echo $i; done
>
>To attempt to get this result ...
>
>crw_1270.crw
>crw_1270.lo.jpg
>crw_1271.crw
>crw_1271.lo.jpg
>
>But I get this error message!
>
>-bash: syntax error near unexpected token `j=`echo $i | cut -d "." -f
>1`'
>
>Can anyone suggest a simple solution or point out what I'm doing
>wrong?!?!  This is really just a "nice to have" but I haven't run into
>this problem in a shell script, only in this extended command method.
>
>Thanks in advance!  

Thanks to all who posted ... putting the addition on the wrong side of
the "do" was exactly it.  If it had been in a script (and in a clean
form) I would have noticed it just as it was pointed out.

I had been trying it off and on for an hour and I got frustrated that
such a simple (?) change was not working BUT I use the same concept
all the time in scripts.

Once again, thanks!  Sorry to be a pain!   :-)

--
------------------------------------------------
         http://www3.sympatico.ca/dmitton
  SPAM Reduction: Remove "x." from my domain.
------------------------------------------------
0
Doug
5/3/2005 10:58:55 PM
On Tue, 03 May 2005 at 22:58 GMT, Doug Mitton wrote:
> 
> Thanks to all who posted ... putting the addition on the wrong side of
> the "do" was exactly it.  If it had been in a script (and in a clean
> form) I would have noticed it just as it was pointed out.

    Even at the command line, it's a good idea to format your commands
    cleanly. The ability to write multi-line commands is one of the
    great advantages of a Bourne-type shell.

-- 
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/ssr.html>
0
cfajohnson (1827)
5/3/2005 11:30:41 PM
Reply: