Skip to content

Conversation

@ilyagr
Copy link
Contributor

@ilyagr ilyagr commented Aug 31, 2025

Makes the information easier to find. It was already mentioned in https://fishshell.com/docs/current/language.html#the-status-variable


``not`` negates the exit status of another command. If the exit status is zero, ``not`` returns 1. Otherwise, ``not`` returns 0.

In order to make it possible for the original status of the command to be recovered, ``not`` does not affect the ``$pipestatus`` environment variable. It only affects ``$status``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if "make it possible" is true.
One can always do

foo | bar | baz
set -l s $pipestatus
if ! [ $s[-1] -eq 0 ]
	...
end

so the other place where it's documented is probably misleading,
we should fix that.

I think we can state the behavior without justification
the way it currently works is reasonably consistent --
by definition, pipestatus is the list of exit codes of each process in a job,
and builtin not negates the status of the whole job,
and doesn't care for processes.

Copy link
Contributor Author

@ilyagr ilyagr Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the other place where it's documented is probably misleading,
we should fix that.

For reference, it says

One difference is that not applies to $status, but not $pipestatus, because it loses information.


the way it currently works is reasonably consistent --
by definition, pipestatus is the list of exit codes of each process in a job,
and builtin not negates the status of the whole job,
and doesn't care for processes.

I find the $pipestatus behavior extremely confusing when doing

foo | not bar | baz

Since not binds stronger than pipe (Update: actually, it binds weaker, so some of this comment is wrong),

not foo | bar | baz

is also confusing.

Perhaps this is never useful; if so it might make sense to prohibit it. If not was only allowed at the end of a pipe (or only in the beginning, but with not foo | bar meaning not { foo | bar }), I think I could see how that makes some sense.


Your workaround disproving the "loses information" argument is interesting and valid, but seemingly not obvious. I didn't think of it myself, and I don't think the person who implemented this was thinking along those lines did either (or not would bind weaker than pipe. Or perhaps this is difficult; not sure it would work sanely with the precedence of && and || behaving intuitively around pipes).

I don't really have a conclusion; the current situation is confusing enough that I'd prefer providing the explanation of "loses information" to not saying anything unless it's fixed. But I'm not sure; I could delete the justification.

Copy link
Contributor Author

@ilyagr ilyagr Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was confused by a buggy prompt I made. I was wrong in my previous comment; { not true | false } && echo blah does print blah. So, not does binds weaker than |.

The default prompt shows it correctly.

(Posted after #11768 (comment))

@krobelus
Copy link
Contributor

krobelus commented Sep 14, 2025 via email

@krobelus
Copy link
Contributor

krobelus commented Sep 14, 2025 via email

@ilyagr
Copy link
Contributor Author

ilyagr commented Sep 14, 2025

The next things I tried were

not true | not false && echo yes | false

and also

{ not not true | not false } && echo blah  # prints blah
{ not true | not false | not true } && echo blah  # does not print blah

:)

In my mind, it's a | not b that's the most cursed. I still don't understand what it does. For a moment, I thought a | not b | c is the same as not { a | b | c }, but the last example above seems to disprove it. Or is that a bug? I certainly can't tell.

The fact that not a | b inverts the whole command is not too bad; I could reason about that, and document it.

@krobelus
Copy link
Contributor

krobelus commented Sep 14, 2025 via email

@krobelus
Copy link
Contributor

krobelus commented Sep 16, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants