0

I'm trying to add a script to check conditions before executing a command in my .cshrc file. This checker script returns 0 if the conditions are insufficient, and 1 otherwise. (I realize this is backwards of convention, but I thought it would be easier for if statements.)

Here is what I've tried, replacing the command with echo "ok":

./checker.sh && echo "ok"

Echoes "ok" even though checker.sh returns 0.

test ./checker.sh && echo "ok"

Echoes "ok" even though checker.sh returns 0, but also suppresses error messages in checker.sh.

if ( ./checker.sh ) then echo "ok" endif

Throws an if-statement syntax error.

I want to turn this into an alias, hence the one-line constraint, e.g.

alias doAction './checker.sh && echo "ok"'

How does one accomplish this with (t)csh without directly calling the command in the checker script?

Thanks!

tomocafe
  • 1,425
  • 4
  • 20
  • 35
  • if you want to execute the code on nonzero exit do `checker.csh || echo "ok"` – agentp Nov 04 '13 at 22:07
  • To avoid the syntax error for single line `if` statements in `csh` do not use `then` and `endif`. For example: `if ( 1 ) echo "y"`. – Andrew Stein Nov 04 '13 at 22:35

1 Answers1

1

I changed the script to exit 0 when there is NO problem, and exit a nonzero number when there is a problem. Then

./checker.sh && echo "ok"

behaves as desired...

Note to others who may read this: the above "test" construct is not equivalent to the C-style if-statement

if(./checker.sh){
  echo "ok"
}
tomocafe
  • 1,425
  • 4
  • 20
  • 35
  • 1
    http://en.wikipedia.org/wiki/Rubber_duck_debugging apparently also applies to posting questions on stackoverflow... – tomocafe Nov 04 '13 at 18:51