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 33635 articles. 0 followers. amosa69 (125) is leader. Post Follow

6 Replies
253 Views

Similar Articles

[PageSpeed] 34
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:
Similar Artilces:

Build problem using Cygwin bash shell for VxWorks 5.5
To: ace-bugs@cs.wustl.edu Subject: [area]: [synopsis] ACE VERSION: 5.5 HOST MACHINE and OPERATING SYSTEM: Windows 2K TARGET MACHINE and OPERATING SYSTEM, if different from HOST: x86 Simulator, VxWorks 5.5 COMPILER NAME AND VERSION (AND PATCHLEVEL): Whatever GNU compiler ships with Tornado 2.2.1 CONTENTS OF $ACE_ROOT/ace/config.h: #if defined (_MSC_VER) || defined (__BORLANDC__) # include "ace/config-win32.h" # undef ACE_HAS_EXCEPTIONS #else # include "ace/config-vxworks5.x.h" #endif CONTENTS OF $ACE_ROOT/include/makeinclude/platform_macros....

Eliminating records from a query that produces a Cartesian Product
Hello All: I'm having a problem that's been baffling me for a few days and I seek counsel here. I have an Access 2000 DB from which I want to run several reports. These reports are essentially the same (albeit for minor formatting differences). To produce these reports, I am drawing from three tables: o Stores '-- Address info for each grocery store in the country o CallTags '-- A list of requests for merchandise return labels (Many requests may come from one store) o Track-No '-- The actual record for each return label (Many labels c...

Running bash inside emacs
Hi I was wondering if it is possible to run a bash shell inside an emacs buffer (where the up and down keys recall commands executed in .bash_history and do not move the cursor around -- the problem with the native shell available in emacs, tab results in command completion, etc.). Thanks. >>>>> Madhusudan Singh <spammers-go-here@spam.invalid> writes: > Hi > I was wondering if it is possible to run a bash shell inside an emacs > buffer (where the up and down keys recall commands executed > in .bash_history and do not move the cursor around -- the problem ...

up-arrow for last command in bash?
I've been trying to figure out how to get the last command to display on the command prompt in bash as opposed to the one I get when I log on as root, like if ( $?tcsh ) then bindkey "^W" backward-delete-word bindkey -k up history-search-backward bindkey -k down history-search-forward endif in my .cshrc in root? when I'm logged as a normal user (bash), I can't get bindkey to work. Probably cause I have no idea what I'm doing when it comes to shell stuff. jeff. -- --- Jeff D. Ham...

print commands with javascript
Hi all, are there any javascipt commands to have a file printed that is not presently shown in any browser window, e.g. a pdf file or a htm page? Best Regards, Henriette van de Haar, Hamburg/Germany Le 6/14/09 3:34 PM, Henriette van de Haar a �crit : > Hi all, > > are there any javascipt commands to have a file printed that is not > presently shown in any browser window, e.g. a pdf file or a htm page? No. JS can't do nothing with any file no yet loaded. (JS can do nothing with the computer) In the Finder, I'm not sure I can print a pdf without to open it before. (h...

BASH: Can bash do this?
I input a long command in bash, and then I found I must run some other command such as man, but I must not run this long command to save it in the history, because it may harmful, Is there a way to save it in the history without running it? On 17 Dec 2006 19:10:48 -0800, "hantechs@gmail.com" <hantechs@gmail.com> wrote: >I input a long command in bash, and then I found I must run some other >command such as man, but I must not run this long command to save it in >the history, because it may harmful, Is there a way to save it in the >history without running it? #c...

Using a query on a query (or view)
In my php page I'm using a mysql database. I want to run a query on a table, then run a second query on the results returned from the first query. In mysql this would be the same as running a query on a table to create a view, and then running a query on the resulting view. What is the php equivalent of this? Thanks. -- John John Victor wrote: > In my php page I'm using a mysql database. I want to run a query on a > table, then run a second query on the results returned from the first query. > In mysql this would be the same as running a query on a table to create ...

Re: [Uniface-L] Use of Undocumented Interrupt command
What's the interrupt command =3F =20 =46ran=E7ois Moritz=20 Hewitt Associates SA Avenue Edouard-Dubois 20, CH-2000 Neuch=E2tel Phone: +41 32 732 34 29 =46ax: +41 32 732 31 00=20 =66rancois.moritz@hewitt.com Hewitt Associates is a leading outsourcing and consulting firm globally and= = in Switzerland=20 delivering a complete range of human capital management services. =46or more detailed information: www.hewitt.ch and www.hewitt.com "jack eisenberg" <jack.eisenberg@accord.ca> Sent by: uniface-l-bounces@uug.org 21.10.2004 19:39 Please respond to...

bash subshell question
I am trying to process the output of a command that produces multi-line output. I am piping the output of the command into a while loop and parsing each line of output. However, since this 'launches' the loop in a subshell, I am not able to get at the results of my parsing outside the loop. A short script representing what I am trying to accomplish is presented below; I am wondering what solutions are commonly employed for this problem? It seems rather inelegant to store the results in an intermediate file .... is this really the only way? I could actually get by with taking actio...

Escape Characters & DB Queries
Hello, I am using Matlab R2006b and the Database Toolbox to connect to various SQL Server and Sybase databases. I generally have no problems forming my queries and passing these to the server, receiving results as expected. However, I am stumped on how to pass a very simple query from Matlab along the lines of: select * from sysobjects where type = 'U' due to the fact that I have to use the single quote in this query. I have tried various string concatenations making use of escape characters, double quotes, etc. but to no avail. As an example: str = ['exec(conn,','...

[9fans] Acme aborts on a pointless Edit command
I was feeling obscene and decided to test out stupid commands in sam and acme. Here's something I didn't expect. Sam: , x g/^/m. no change to file Acme (Edit): , x g/^/m. aborts in /sys/src/cmd/acme/ecmd.c:/^move It aborts because "move overlaps itself" but the question I have is, should it work like sam and do *visually* nothing at all? Anthony P.S. This came about because I was trying to find a way to move lines matching a certain pattern to the beginning of a file (like g/pattern/m0 in ed). Is there a nice way to do this in sam? Something that works like the ed com...

Using pine from the command line
Hello! OS: AIX 4.3.2 Pine 4.32 I have posted this on the pine user group site and thought someone who uses AIX day-in-day-out may actually be better able to answer this question. ******************************* pine posting: Before I ask I recognise that AIX 4.3.2 is not one of the ported options on the pine website. (The highest is 4.2). [Anyone happy to prove me wrong and point me in the direction of an AIX 4.3 pine version will be warmingly welcome!] Believing (naively?) that I can get away with buillding for 4.2 on 4.3 I am trying to apply the "outgoing.patch" listed by Mr Ch...

Re: Replacing the PASSWORD command #4
Re: > Won't a UDC named PASSWORD do just this? No... :EDITOR (and anything calling the COMMAND, not HPCICOMMAND, intrinsic) won't see a UDC. -- Stan Sieler sieler@allegro.com www.allegro.com/sieler/wanted/index.html * To join/leave the list, search archives, change list settings, * * etc., please visit http://raven.utc.edu/archives/hp3000-l.html * ...

using a query to change a yes/no field
I have a database that is going to be used to do billing on orders. I sent up a field for each record that is called Billed and is a yes/no field. I want to do a query that will pull all the records that haven't been billed, issue them an invoice, then mark the billed field in those records to yes. Any ideas? Thanks in advance! -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 When you "issue" the invoices is when you'd mark each order record as "billed." If you're doing this from a printed report you can use the report's Detail_Print() subroutine. E.g.:...

CDE Command
To get from a command line into X I use #xinit /usr/dt/bin/Xsession Could some one tell me the command to get from the command line into CDE. Thanks Basil RS/6000 Power Station 7011-250 256mb GT4e Video 6091-19i terminal Netscape 4.75i AIX4.3.3.0 Basil Holloway wrote: > To get from a command line into X I use > #xinit /usr/dt/bin/Xsession > > Could some one tell me the command to get from the command line into CDE. > > Thanks > Basil > RS/6000 Power Station 7011-250 256mb GT4e > Video 6091-19i terminal Netscape 4.75i AIX4.3.3.0 > > Simply 'xini...

(patch for Bash) XML + Bash
After looking at Expat XML parser (www.libexpat.org), I've decided to patch a simple interface to Bash shell. Mainly, so that Gawk can't brag about it having an interface. :-) In C code, you would register callback functions, and Expat will call them as it encounters various XML components. So, I made it similar in shell. That is, you specify shell functions/commands to be called. You still have to do some bookkeeping, but I think it's easier in shell. Of course, you can do other things in C which you can't do in shell. Ref: http://freshmeat.net/projects/bashdiff/ -...

Desktop on Command
Works fine for remote connection from : OS/2 and Netscape but not (on the same machine) with : OS/2 and IBM Browser - the file transfer window opens but not the remote desktop. Is there something wrong with my java settings? Doesn't work at all with Win98Lite with Opera, or with Win2KPro and XP with IE. BTW it works BEST with : SuSE 8.2 and Konqueror :-) BTW (2) after a fresh install of Netscape then Mozilla on XP neither would open - Is there a Mozilla-killa in XP? "Philip Nicholls" <prnicho@attglobal.net> wrote in news:4005e93c_4@news1.prserv.net: I use DOC with...

difference between IDLE and command line
New to Python, and just had something strange happen. I've been running my new code in IDLE running in windows. My IDLE version shows as 1.2.1, Python version displaying in IDLE is 2.5.1. I have been editing my code in UltraEdit then testing in IDLE by choosing open, then F5. I didn't see an easy way to refresh in IDLE, so each edit I've been closing the file (not IDLE itself), then opening again. Since IDLE does not keep track of what directory I last opened from, this gets tedious, so I decided to run my code from the command line. Here's where it got interesting f...

query should use an index?
hello, i've got a table that looks like this (irrelevant data removed); create table test ( id serial primary key, t_end timestamp); there's an index: create index test_t_end on test(t_end); can or should a query like: select login,t_end from test order by t_end desc; use the index? explain says it does a sequential scan and sort. but it seems to me that if it's possible for the postgresql to use the index to seek to the last record and then step backward, then it could use the index. but of course i don't know anything about postgresql inter...

Input from PBS bash file into matlab
Hi, I have a simple question but I can't find any documentation anywhere. I'd like to write a bash script which request a certain number of nodes in a look, then according to the node number, the number is then in-putted as an argument in a matlab function and the matlab function is run. The real trouble I have is that I have to use scripts, because I have to use the deploy tool and the deploy tool only works with scripts. So somehow my script which I have already compiled using the compile tool should be able to read the pbs output. I dont believe this is possible which is a...

bash: javac: command not found problem
Hi: I am new to Linux/unix. I was trying to compile a simple hello world java program in my local and a remote (after ssh from my local machine) linux machines, but both i got "bash: javac: command not found" errors. When i used command "java -version" on both machines, I got "java version 1.6.0_02, java TM/SE Runtime Environment (build 1.6.0_02.605), Java HotSpot(TM) client VM ....." on my local PC, and got "java version 1.4.2, gcj (GCC) 3.4.6.20060404 (Red Hat 3.4.6-3) ......" on the remote server. When i used command "find / - name javac" t...

command/translate UDF
Hi all, I created translation: function NameUDF( var1:=0, var2:='X', var3:=.F. ) => PPO: function NameUDF( var1, var2, var3 ) .... .... return nil but how to translate so mixed ? function NameUDF( var1, var2:='X', var3, var4:=0 ) => PPO: function NameUDF( var1, var2, var3, var4 ) ... .... return nil Regards, Eric Developer Systems Sorry I can't understand your question. "Eric.Developer" <emm.developer@gmail.com> wrote in message news:4ae4e5cc-0a42-4634-a0ab-73055dabe1ef@i13g2000yqd.googlegroups.com... > Hi all, > > I created translation...

input command
Is there a way to to get the input/minput command to find an exact match? I want it to find only the string: login: That's a single space followed by login: and no trailing spaces. Using the UNIX grep command I would find it using: grep '^ login:$' file_name Instead, input/minput is catching any line with login: within it, such as: Last login: Tue Aug 17 16:03:20 from 10.195.10.8 Thanks -- +-----------------+----------------------------------+------------------------+ | . . |Kenny Broezell |phone :(847) 342-5633| | ...

Working with bash and cat
I just downloaded bsh204br3.zip from current but when executing the following script I get an error "Bad file descriptor (EBADF)": echo 1 | cat I tried downloading the latest beta bsh205bbr3.zip but then whenever I pipe something into cat, nothing gets output to the screen. Is there a more recent version of bash I can download which fixes these problems? Matt D. Bash pipe doesn't work at all with any of the 2.05 binaries. All of these fail: sh.exe sh-2.05$ echo 1 | cat sh-2.05$ echo 1 | while read a; do echo $a; done sh-2.05$ echo 1 | (read a &...

query syntax error!!
hi, INSERT INTO fichiers (name, use, filename, filetype, target) VALUES ('a l\'adresse des anciens', 'blah blah blah', 'annonce_legale.odt', 'application/vnd.oasis.opendocument.text', 'courtier') I've been trying to find what's wrong with that query, I just can't figure it out. On 8 Dec, 10:10, End of Road <jo...@cretin.fr> wrote: > hi, > > INSERT INTO fichiers > (name, use, filename, filetype, target) > VALUES > ('a l\'adresse des anciens', 'blah blah blah', 'annonce_legale.odt', &...