On Sat, 7 Dec 2013, Daniel Barnes wrote:
> There's a few issues with this that causes this behavior:
> 
> The way "or" works, it waits until the first command has been executed, then
> moves on to the second. The "if" only seems to be taking the first command,
> and the "or" is actually being executed inside the block:
> 
> if false;
>   or true;
>   echo yes;
> ..
> 
> 
> So, first `false` is being evaluated to.. false, then it is skipping right to
> the "else" block. Therefore, the output is "no".

Correct.

> In the case you would want to make sure the "or" applies in the first
> statement, you should use parentheses:

eek. You should use blocks, not command substitutions.

> set myTest (false; or true)
> echo $status # 0
> set myTest (false; or false)
> echo $status # 1
> set myTest (true; or false) # note: the second "false" is not evaluated
> because the true was already true.
> echo $status # 0
> 
> if $myTest; #...

The argument to your conditional here is the output of 'true; or false', 
not the return value. You could do `set myTest (true; or false); if 
$status`: see https://github.com/fish-shell/fish-shell/issues/547 to see 
why this works.

> Also, one other thing to mention: the `test` command has an -o (or) and -a
> (and) switch, made for using these operators (though I can't figure out how
> they work, I seem to be receiving weird results and thus can't provide and
> example... test (false) -o (false) has an exit status of 0 for me). Maybe it
> will help for what you're doing, it seems to be more aimed at making tests for
> things like that.

Your test command compares the output of the command substitution, not the 
return value. `false` produces no output, so the command substitution 
expands to nothing; thus you are effectively running `test -o`, which (per 
the POSIX standard [1]) is true.

The `-o` and `-a` operators are for comparing expressions which are valid 
test expressions in their own right. For example, you could do `test -d 
/etc -a -r /etc` to see if /etc/ is a directory that you can probably read 
from.

David Adam
zanc...@ucc.gu.uwa.edu.au

[1]: http://www.unix.com/man-page/POSIX/1/test/
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to