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
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
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
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
Forgot to send to the list.
- Original message -
From: Greg Reagle greg.rea...@umbc.edu
To: Marcin Zajączkowski msz...@wp.pl
Subject: Re: [Fish-users] Problem with -n in a conditional statement
Date: Tue, 11 Nov 2014 17:44:37 -0500
On Tue, Nov 11, 2014, at 05:29 PM, Marcin Zajączkowski
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
On Tue, Nov 11, 2014, at 05:45 PM, Marcin Zajączkowski wrote:
Another question related to fish scripting. How can I set a value to a
variable to be able to use it in `if`?
if test $myBool
...
end
The shell's only notion of true and false (this is true for all unix
shells that I know) is
On 2014-11-11 23:44, Greg Reagle wrote:
On Tue, Nov 11, 2014, at 05:29 PM, Marcin Zajączkowski wrote:
The next problem I encounter is how to check two variables in one if
statement.
There are several ways of doing this. Here is one:
set -q $COLUMNS $LINES; if test $status = 2; echo
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
On Tue, Nov 11, 2014 at 5:51 PM, Glenn Jackman
Well I was totally wrong here. Of course this is not a bug in fish or
the man page, it is my mistake. I shouldn't have used the dollar sign
in set -q. Here is corrected code:
if set -q COLUMNS LINES; echo both defined; end
On Tue, Nov 11, 2014, at 05:45 PM, Greg Reagle wrote:
Forgot to
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
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
On Tue, Nov 11, 2014, at 05:51 PM, Glenn Jackman 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.
Just to be clear, it's relatively straightforward to write your own custom
completions in fish.
There just isn't one yet that makes the distinction that you want.
You can create your own expansion functions in ~/.config/fish/functions
and your own gvim completetions in
On Tue, 11 Nov 2014, Greg Reagle 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
15 matches
Mail list logo