LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   osx bash script help? (https://www.linuxquestions.org/questions/programming-9/osx-bash-script-help-523638/)

babag 01-28-2007 08:24 PM

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


wjevans_7d1@yahoo.co 01-28-2007 09:11 PM

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.

babag 01-28-2007 10:26 PM

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

wjevans_7d1@yahoo.co 01-29-2007 05:38 AM

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.

babag 01-30-2007 07:32 PM

thanks wjevans! with your help i was able to get it to run.


All times are GMT -5. The time now is 10:03 PM.