On 2014-11-11 22:49, Glenn Jackman wrote:
> You might want to test if the variable is set first:
Thanks Glenn, that works.

The next problem I encounter is how to check two variables in one if
statement. I tried with |and| keyword and with |test| joined with |-a|,
but it fails?

|if set -q SSH_TTY and set -q SSH_CLIENT
if test ( set -q SSH_TTY )\ -eq 0
if test ( set -q SSH_TTY ) -eq 0|

Marcin

>
>     $ 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
> <mailto: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
>     <mailto: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 <mailto:jack...@pythian.com>
> Tel: +1 613 565 8696 Ext. 1478
> Mobile: +1 613 808 4984
> www.pythian.com <http://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