LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-28-2007, 08:24 PM   #1
babag
Member
 
Registered: Aug 2003
Posts: 419

Rep: Reputation: 31
osx bash script help?


trying to make bash script in osx that continually looks at a
directory and runs an app called dcraw when there are at least 2
.nef files in that directory. getting a syntax error on the line
that starts with y0.

the way i've been trying to write it is to have the script watch the
directory for input; that's the count function. once there's at least
2 files it jumps to the processing function where it puts the name
of the first file into a variable (A) and gives variable A to the
dcraw app as the file to process. the idea being that files are
always processed in order this way.

if the number of files drops below 2 the script would return to
counting until there are once again 2 or more .nef files.

probably lots of inelegant parts to this but it's the y0 line that's
got me hung up right now. thanks in advance for any help. the script
follows:


Code:
#!/bin/bash

# count nefs
function count {
        n=$(ls/Volumes/1TB_Raid-00/1TB_Raid-00/receiving | wc -l)
        echo $n
}

# process
function process {
        while [ $n -gt 1 ]; do
                for A in /Volumes/1TB_Raid-00/1TB_Raid/receiving/*.nef
                        y0=`echo "$A" | awk -F"." '{print$1}'`
                        dcraw -w -o 2 /Volumes/1TB_Raid-00/1TB_Raid-00/receiving/"y0".nef
                done
        done
}

count

if ($n -gt 1) then
        process
else
        count
done
 
Old 01-28-2007, 09:11 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Do you see that "; do" you have at the end of the "while" line?

You need another one just like it at the end of the "for" line (the next one in the script).

Don't forget the semicolon.

Hope this helps.
 
Old 01-28-2007, 10:26 PM   #3
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
thanks wjevans. will look at that when i get back on the
box in the morning. didn't get the error on that line,
though. when the error came up it displayed the next line.
would omitting the "; do" on the previous line cause bash
to display the error for the next line? is that how bash
does things?

thanks again,
BabaG
 
Old 01-29-2007, 05:38 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Yep, that's how bash does things.

The reason it bombs on the next line is that even though the recommended fix is on the line I said it's on, there is technically no error on that line. It's just that bash expects certain things _after_ what's on that line, and by the time it reads the next line, it hasn't found them. If that makes any sense.

Incidentally, part of where you put the fix is a matter of style. Here's the style you use:

Code:
for A in blah blah; do
  echo $A
done
You could just as easily do this:

Code:
for A in blah blah
do
  echo $A
done
Note the missing semicolon. In the first example, the semicolon alerts bash to where the "blah blah" ends; in the second example, the end of line does the same thing. In your situation, bash gets to the y0 line, thinks it's still evaluating the "blah blah", and croaks.

Incidentally, you get the same two choices of style in the previous "while" line. Between the two style examples above in the reply you're reading now, I chose the first one when I wrote my original answer, because that made the style of your "for" statement the same as the style in your "while" statement.

(I use the other style myself, because that makes the "do" line up with the "done", and for me that makes things more readable. This is a religious issue.)

Hope this helps.

Last edited by wjevans_7d1@yahoo.co; 01-29-2007 at 05:57 AM.
 
Old 01-30-2007, 07:32 PM   #5
babag
Member
 
Registered: Aug 2003
Posts: 419

Original Poster
Rep: Reputation: 31
thanks wjevans! with your help i was able to get it to run.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script hangs upon starting another script in the background masea2 Linux - Software 4 11-13-2006 05:18 AM
building a bash script from an install script paranoid times Programming 6 07-29-2006 03:24 AM
Bash script - executing a script through subdirectories bubkus_jones Programming 5 04-24-2006 05:05 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration