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
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 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
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.
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
10 matches
Mail list logo