You might want to test if the variable is set first:

$ function ntest
>           if not set -q NOT_SET_VARIABLE
>               echo "not set"
>           else if test -n $NOT_SET_VARIABLE
>               echo "Non-zero"
>               echo $NOT_SET_VARIABLE
>           else
>               echo "Zero length"
>           end
>   end
> $ set -e NOT_SET_VARIABLE
> $ ntest
> not set
> $ set NOT_SET_VARIABLE foo
> $ ntest
> Non-zero
> foo
> $ set NOT_SET_VARIABLE ""
> $ ntest
> Zero length



On Tue, Nov 11, 2014 at 4:37 PM, Marcin Zajączkowski <msz...@wp.pl> wrote:

>  Hi,
>
> I wanted to write a script which display different prompt for session made
> through SSH. SSH should set SSH_CLIENT and SSH_TTY variables, so it should
> be easy to check. Unfortunately I am unable to write working if for those
> two cases. In the end it seem that even simple test with “-n” from manual
> (there with $MANPAGE) doesn’t work for me. Following function:
>
> function ntest
>     if test -n $NOT_SET_VARIABLE
>         echo "Non-zero"
>         echo $NOT_SET_VARIABLE
>     else
>         echo "Zero length"
>     end
> end
>
> returns:
>
> Non-zero
> <empty line>
>
> Of course variable is not set:
>
> $ echo $NOT_SET_VARIABLE
> <empty line>
>
> What is wrong in that code? How can I check if a variable is set?
>
> Fish 2.1.1, Fedora 21.
>
> Marcin
> ​
>
>
> ------------------------------------------------------------------------------
> 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

-- 


--



------------------------------------------------------------------------------
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