On Fri, Dec 19, 2008 at 06:09:59PM -0600, Mike Miller wrote:
[snip]
> Have any of you done this kind of thing before? Let me know if you know
> of code for converting scripts or have ideas on how to make the thing
> below do more or work better.
I don't know about your scripts, but most of the ones I write have a bunch
of if statements and cases in them. Such statements can be a bit tricky in
bash at first due to all of the implicit typing. A few pointers:
if [[ ... ]]; # this is a conditional expression
Example:
if [[ $foo == "bar" ]]; then echo $foo; fi
if (( ... )); # this is an arithmetic expression
Example:
if (( $num < 10 )); then echo "Oops!"; exit; fi
(( )) is also a nice way to do boolean conditions in bash, I've found.
let's say you want to exit if a command has failed:
mv foo bar;
if (($?)); then "Couldn't rename foo!"; exit 1; fi
$? is the exit status of the last command run. If it's 0, i.e. the last
command exited without error, the if will be false.
HTH,
Gabe
--
Gabe Turner gabe at msi.umn.edu
UNIX System Administrator,
University of Minnesota
Supercomputing Institute http://www.msi.umn.edu