質問

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!

役に立ちましたか?

解決

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"
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top