On 2014-11-12 00:03, Marcin Zajączkowski wrote:
> On 2014-11-11 23:54, Glenn Jackman wrote:
>> Marcin, applying this to the 2-variable question:
>>
>> $ test "$SSH_TTY$SSH_CLIENT"; and echo "not empty"; or echo "unset or empty"
>>> unset or empty
>>> $ ssh localhost
>>> [...]
>>> $ test "$SSH_TTY$SSH_CLIENT"; and echo "not empty"; or echo "unset or
>>> empty"
>>> not empty
> 
> Nice trick Gleen. That works fine when as a substitution of `or`
> operator (just one variable set makes the test return `true`).

Sorry, Gleen -> Glenn.

Marcin


>> On Tue, Nov 11, 2014 at 5:51 PM, Glenn Jackman <jack...@pythian.com> wrote:
>>
>>> I suspect what is happening (this is true in bash, I'm speculating about
>>> fish) is that an unset variable is substituted with nothing (not the empty
>>> string, but with nothing). Then the `test` command receives exactly one
>>> argument: "-n". When `test` is given a single argument, the result is true
>>> if that argument is not empty. This is true for the string "-n".
>>>
>>> So another way to write the test is simply
>>>
>>> if test $NOT_SET_VARIABLE; ...
>>>
>>>
>>> Demo
>>>
>>> $ set -q foobar
>>>> $ test $foobar; and echo "not empty"; or echo "unset or empty"
>>>> unset or empty
>>>> $ set foobar ""
>>>> $ test $foobar; and echo "not empty"; or echo "unset or empty"
>>>> unset or empty
>>>> $ set foobar abc
>>>> $ test $foobar; and echo "not empty"; or echo "unset or empty"
>>>> not empty
>>>
>>>
>>>
>>>
>>> On Tue, Nov 11, 2014 at 5:33 PM, Greg Reagle <greg.rea...@umbc.edu> wrote:
>>>
>>>> That's very interesting.  I get the same problem.  I don't think
>>>> anything is wrong with your code.  I think something fishy is going on
>>>> with fish, but I don't know what.  It looks like it might even be a bug
>>>> in fish.  I would expect test -n to be the opposite of test -z, but that
>>>> is not true sometimes.
>>>>
>>>> There are a few workarounds.
>>>>
>>>> I find that test -z works fine.
>>>>
>>>> Another way to test a variable is
>>>>     if test ab"$variable"cd = abcd; echo zero; else; echo non-zero; end
>>>>
>>>> --
>>>> http://www.fastmail.fm - Access all of your messages and folders
>>>>                           wherever you are
>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Comprehensive Server Monitoring with Site24x7.
>>>> Monitor 10 servers for $9/Month.
>>>> Get alerted through email, SMS, voice calls or mobile push notifications.
>>>> Take corrective actions from your mobile device.
>>>>
>>>> http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
>>>> _______________________________________________
>>>> Fish-users mailing list
>>>> Fish-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/fish-users
>>>>
>>>
>>>
>>>
>>> --
>>> *Glenn Jackman*
>>> Senior Software Developer
>>>
>>> *Pythian - Love your data*
>>> jack...@pythian.com
>>> Tel: +1 613 565 8696 Ext. 1478
>>> Mobile: +1 613 808 4984
>>> www.pythian.com
>>>
>>
>>
>>
> 
> 


-- 
http://blog.solidsoft.info/ - Working code is not enough


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&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