BASH Command Query?!?!

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply Doug 5/3/2005 1:03:09 PM

See related articles to this posting


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
Reply davideyeahsure (1282) 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply cfajohnson (1827) 5/3/2005 11:30:41 PM
comp.os.linux.misc 33425 articles. 20 followers. Post

6 Replies
189 Views

Similar Articles

[PageSpeed] 1


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Command completion within command substitution (bash)
I have a function called 'a' that has command completion associated with it. This works. I would like it to complete as well within command substitution, so that 'cp zut $(a foob<TAB>)' will complete to foobar. So far I have no luck in researching this, possibly because the search terms I can think of (basically the subject) are not very specific. I've noted that completion works for regular commands such as ls within command substitution. Is this possible, and how? Stijn ...

Bash
Hello, I am using $ bash --version GNU bash, version 2.05b.0(1)-release (i586-mandrake-linux-gnu) Copyright (C) 2002 Free Software Foundation, Inc. When I store the result of a command substitution in a variable and 'echo' it to stdout, the multibyte characters do not appear. These multibyte characters seem to be stripped out by Bash: # wanted result $ wc -c lib.ja.po 590 lib.ja.po # attempt 1 $ text=$( < lib.ja.po ) ; echo ${#text} 462 # attempt 2 $ text=$( < lib.ja.po ) ; echo $text | wc -c 451 # attempt 3 $ ( while read -r text ; do echo $text ; done < lib.ja.po ) | w...

How to break a bash command into an array consisting of the arguments in the command?
Hi, Suppose that I have a bash command in a string, e.g. cmd.sh a 'a b' ' ' I want get an array consisting of "cmd.sh" "a" "a b" "\n". Is there a robust way to do so in perl that can handle all the possible cases? Thanks. Peng Yu <pengyu.ut@gmail.com> wrote: >Suppose that I have a bash command in a string, e.g. > >cmd.sh a 'a b' ' >' > >I want get an array consisting of "cmd.sh" "a" "a b" "\n". Is there a robust way to do so in perl that can ...

matlab command specgram and mesh plot command query
Gd day everyone, I have a few questions which need some clarifications desperately. Currently i have used a specgram command in matlab to do a short time fourier transform or STFT on a signal. my command goes like: nfft = 512; Fs = Fsnew; window = 51; num_overlaps = 1; [C1,F1,T1] = specgram(signal, nfft, Fs, window, num_overlaps); % Computes the STFT of x Matlab returns me a -F1 array of 257 by 1 -T1 array of 527 by 1 -and a C1 array of 257 by 527 Is there a way to make my F1 and T1 of the same size? I then did a coherence estimate by adding up the sum of the cross terms, and taking its a...

command query
Hi Group, I have a question regarding a unix command that maybe someone can help me with? I want to display CPU info on screen - ie: Processor type, speed... I can get this information from the 'dmesg' command but is there any way to split up this information, by that I mean, can I get the processor type, speed from seperate commands? Also, I want to print on screen, the number of users currently logged on that are members of my group. I am doing this by: 'who|groups|wc -l', but this isn't correct. Does anybody know what the right command for this is? Thanks to all in...

query: what was this command?
I read in a magazine the other day that there's a simple thing you can type in word that causes it to repeat a word or phrase you put in brackets, as many times as you specify. It was a really simple little command which I memorized..then immediately forgot. Can anyone here suggest what it might have been? Thanks in advance. ...

mysql 1054 error only occurs when running query via PHP script, but the same query is okay when running from command line.
Hello, I've been stuck on this problem and I don't know what the cause is. I have a table with the following format (see below). When I run a query via PHP script, I keep getting error# 1054. INSERT INTO uut_build (`id`, `uut_s_n`, `pn_260`, `rev_260`, `date_260`, `pn_700`, `rev_700`, `date_700`, `pn_800`, `rev_800`, `date_800`) VALUES ('02daa9de-d414-43d2-b6b3-b8c1a6551f8b', 'peter', '26009123-02', '01', '2009-07-28', '', '', '0000-00-00', '', '', '0000-00-00') MySQL Error: 1054 (Unknown column...

bash [ ] braces query
why do we use the braces for some test and not all 2004-10-12, 06:23(-07), dbhack: > why do we use the braces for some test and not all The "[" command is a command dedicated to various tests. It evaluates its argument as a test expression and returns a 0 exit status if it evaluates to true of a non-zero value otherwise. The "if" statement in shell is: if list; of; commands then other; list; of; commands; else yet; another; list; of; commands; fi Where the <then-list-of-commands> is executed if the <if-list-of-commands> has a zero exit status. The "...

error on which command in bash
I am running bash 2.051.0(1)-release on Tru64 4.0f and when I run the which command I get this: Unmatched ". I don't see this message on any other command. I have this same setup on three other boxen and they don't exhibit the same behaviour. I checked my .bash_profile for oddites, but found none. Any hints? fyb -- This is my sig On 2004-05-26, fybar wrote: > I am running bash 2.051.0(1)-release on Tru64 4.0f and when I run the > which command I get this: > > Unmatched ". > > I don't see this message on any other command. I have this same setup...

bash : what is wrong of this if command
Hi, I just come to bash from csh, there is one problem in using if command: bash-2.05b$ if [ `uname`=="SunOS" ]; then echo haha; fi haha bash-2.05b$ if [ `uname`!="SunOS" ]; then echo haha; fi haha Do you see the problem of the above 2 if command. If I run "uname", I see "Linux" returns. Thanks. On Fri, 25 Mar 2005 at 17:08 GMT, clinton__bill@hotmail.com wrote: > Hi, > I just come to bash from csh, there is one problem in using if > command: > > bash-2.05b$ if [ `uname`=="SunOS" ]; then echo haha; fi > haha > ba...

test command in bash
How do I combine commands in bash? There is obviously something wrong with what I am doing here since I am only expecting the "hhh" in the first case but not the second. $ pr= $ bk=RRR $ if [ -z $pr ] && [ -n $bk ] ; then echo hhh; fi hhh $ if [ -n $pr ] && [ -n $bk ] ; then echo hhh; fi hhh Duh! I have to use quotes. $ if [ -n "$pr" ] && [ -n "$bk" ] ; then echo hhh; fi $ if [ -z "$pr" ] && [ -n "$bk" ] ; then echo hhh; fi hhh "RolandRB" <rolandberry@hotmail.com> writes: > Duh! I hav...

Puzzeling up a bash command
Hello, I am quite new to bash scripting and having a problem writing script with parameters that only appear conditional. The time being I do it by using string operations, would be nice if you'd tell me a way to do this right, but I am open to other methods, too... I have heard about xargs, but I am not sure wether it is usable in this case. The problem in the example are the double quotes. Once they are a string they stay string, even if I use the whole string as parameter. Since the $INFILE dor example is most likely to contain white spaces, and it surely does not start with the addi...

help on a bash command
Hi, I'm a newbie to unix, and I use the bash shell for my work. I saw the command: bash$ :(){ :|:&};: as part of somebody's sig at a forum. Since I had no clue as to what it meant, I tried it on my command prompt and my computer hung :| I couldnt decipher the command by either skimming the man page or googling. Can someone break down whats happening here? Thanks in advance, and sorry if this is the wrong forum to post such stuff. thanks, marq On 2005-11-07, railrulez@gmail.com wrote: > Hi, > > I'm a newbie to unix, and I use the bash shell for my work. I saw the ...

SPAWN bash commands
Hey I am working on some astronomical data reduction and some parts on my pipel= ine rely on calling executables which are normally called in a regular shel= l. SPAWN works very well for most cases, but some routines can't be execute= d correctly because they are missing some executables themselves. For instance: Calling Scamp (http://www.astromatic.net/software/scamp) can't download an = external reference catalog and with Montage (http://montage.ipac.caltech.ed= u) I can't run the batch executables. They result in the error: [struct st= at=3D"ERROR", msg...

Queries for host command
Dear All, I am new to DNS and trying the command , but getting following error, # host www.linuxhomenetworking.com ;; connection timed out; no servers could be reached # host 65.115.71.34 ;; connection timed out; no servers could be reached I am behind my institute's proxy ( 172.18.10.1 ) ..... what should i do to run host command..... Pls help.. Regards, -Ashish In article <ef94d9$njj$1@sf1.isc.org>, "ashish.sachan@gmail.com" <ashish.sachan@gmail.com> wrote: > Dear All, > I am new to DNS and trying the command , but getting following...

HELP for Query commands
Can anyone tell me where to find `help' on commands in SQL Query for VO-Reports e.g. SELECT, FROM, WHERE, ORDER BY. I see these in the query built by VO but are there others and can I get info on how to use them? Thanks tlyoung@cwjamaica.com wrote: > Can anyone tell me where to find `help' on commands in SQL Query > for VO-Reports e.g. SELECT, FROM, WHERE, ORDER BY. > I see these in the query built by VO but are there others and > can I get info on how to use them? It is a language called SQL, although it seems each ODBC driver/RDBMS talks a different versio...

How to query pid of command?
Hi Folks, is there a way to query the pid if i only know the process cmd/name? For exampe, ps displays something like: PID TTY TIME CMD 7890 ? 00:00:00 mydaemon (How) is it possible to query the pid of mydaemon? Please let me know and thanks in advance.... Hi Folks, is there a way to query the pid if i only know the process cmd/name? For exampe, ps displays something like: PID TTY TIME CMD 7890 ? 00:00:00 mydaemon (How) is it possible to query the pid of mydaemon? Please let me know and thanks in advance.... What i'd like to do is to s...

bash for loop embedded command
I would like to use "find" within a for loop to locate files and do something to them. Somethin like: for xx in [find . -name "*.bak"] ; do rm $xx done My problem is that I can't figure out how to embed the find so that it's output is used to populate the list. Thanks Dave On 16 Aug 2003 14:38:08 -0700, Dave <dave1_nyc@hotmail.com> wrote: > I would like to use "find" within a for loop to locate files and do > something to them. Somethin like: > > for xx in [find . -name "*.bak"] ; do > rm $xx > done > > M...

-bash: fop: command not found
Hi all! I'm quite new to FOP and have spent the day on this Mac O 10.3.4 trying every possible installation combination I can think of but I must be missing something very very basic that none of the mai sites feel the need to mention, as the command line still spits bac nothing but -bash: fop: command not found Can anyone give me a hint as to what presumably obvious error I a making? Many thanks - timodheer ----------------------------------------------------------------------- Posted via http://www.forum4designers.co -------------------------------------------------------------------...

running a bash command with a timeout
Is there a nice way to run a command with a timeout around it? For example sometimes I query ~100 servers about their status using a command like so: for i in $(seq 1 99); do ipmitool 172.16.0.${i} status; echo $i ; done But let's say one server (say, 172.16.0.4) is hung or unresponsive. Then the loop never goes beyong this to 172.16.0.5 etc. Ideally, I'd like the loop to wait for, say, 10 secs. and if no response then go to the next index in the loop. Any nice way to do this? Ideally on the bash command line. But I am also open to other ideas. Of course, had...

bash command substitution question
hi, I am trying to determine the diff between two different "ls -R"s, like so: diff $(ls -R directoryone) $(ls -R directorytwo) But this issues an error, since each of the ls commands returns multiple results, I think, so diff thinks there are two many args. The error message says there is an extra operand. What am I doing wrong? Is there a way to tell bash that the multiple things returned by $(ls -R dirone) should be treated as a single file? thanks, j. In article <bfhtfo$2v2i$1@agate.berkeley.edu>, jano <jnana4@DELETEhotCAPSmail.com> wrote: >hi, > &g...

How come bash does not have stop command?
C shell has a stop command for job control... Does a similar command exist in bash? 2003-11-29, 16:35(-08), Viktor: > C shell has a stop command for job control... Does a similar command exist in bash? kill -stop % to stop kill -cont % or bg or % & to continue in background % or fg to continue in foreground -- St�phane ["Stephane.Chazelas" at "free.fr"] Stephane CHAZELAS <this.address@is.invalid> wrote in message news:<slrnbsjnvg.42.stephane.chazelas@spam.is.invalid>... > 2003-11-29, 16:35(-08), Viktor: > > C shell ...

bash timestamp command history
Hi, I've posted this to comp.unix.solaris, but haven't got much response. I happened onto this newsgroup and hope it is more appropriate. Fred -------- Original Message -------- Subject: bash timestamp command history Date: Fri, 13 Feb 2004 05:01:24 -0500 I'm migrating from tcsh to bash. When I type "history" in tcsh, I get a list of previous commands, each with a time stamp. Is there a way to get this time stamp when viewing previous commands with bash's history command? in comp.unix.shell i read: >I'm migrating from tcsh to bash. When I type >&quo...

AWK command in Bash alias
When I try from the prompt the following command: awk 'BEGIN { print '$books' / '$authors', "books per author" }' >> listc.txt It work very well. I wish to put it in an alias: alias lstpntrc="awk 'BEGIN { print '$books' / '$authors', "books per author" }' >> listc.txt" I get: awk: syntax error at source line 1 context is >>> <<< awk: illegal statement at source line 1 missing } I defined the files "listc.txt" and the variables "books"...