You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I invoke a shell from ranger, the environment variable RANGER_LEVEL can be used to detect that ranger is the parent process. However, it seems that it doesn't work with fish.
To answer your question: test -n $RANGER_LEVEL is always true. It doesn't matter whether the shell was spawned by ranger or not. But the example mentioned above says:
If the variable MANPATH is defined and not empty, print the contents:
if test -n $MANPATH
echo $MANPATH
end
It's obviously essential that the variable is defined. I expected test -n would be false if not.
Anyway, my problem has been solved. The thread can be closed. Thanks for the quick answer.
Oh, I get it. This is the nasty case where an undefined variable expands into zero arguments, i.e. test -n, and then the POSIX requirements on test require it to return true because it was passed exactly one argument. The example from the docs should really read test -n "$MANPATH".
Activity
zanchey commentedon Jul 23, 2014
When you say that it is not available, do you mean that it does not appear in the output of
set?donatellaq commentedon Jul 23, 2014
I've found the MANPATH example here. Thus, I tried
which didn't work.
But you're right. It can be found with the
setcommand. So I can useOr what would be the current method?
Thank you so far
Donatella
ridiculousfish commentedon Jul 23, 2014
The most canonical way would be:
Can you please explain "didn't work?" What did you see and what did you expect to see instead?
donatellaq commentedon Jul 23, 2014
That's it.
To answer your question:
test -n $RANGER_LEVELis always true. It doesn't matter whether the shell was spawned by ranger or not. But the example mentioned above says:It's obviously essential that the variable is defined. I expected
test -nwould be false if not.Anyway, my problem has been solved. The thread can be closed. Thanks for the quick answer.
ridiculousfish commentedon Jul 23, 2014
Oh, I get it. This is the nasty case where an undefined variable expands into zero arguments, i.e.
test -n, and then the POSIX requirements on test require it to return true because it was passed exactly one argument. The example from the docs should really readtest -n "$MANPATH".ridiculousfish commentedon Jul 23, 2014
Let's leave this open to track updating the example from the docs.
donatellaq commentedon Jul 24, 2014
Thanks for the explanation. I understand now, why
test -nbehaves how it does. By the way, it's even more confusing in zsh:But now it becomes off topic.