Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command substitutions should modify $status #547

Closed
ridiculousfish opened this issue Jan 27, 2013 · 2 comments
Closed

command substitutions should modify $status #547

ridiculousfish opened this issue Jan 27, 2013 · 2 comments
Milestone

Comments

@ridiculousfish
Copy link
Member

This is a proposal to make command substitutions modify $status. Currently, the exit status of command substitutions is just discarded.

This will usually have no effect, because command substitutions must be passed to another command, which will overwrite status:

echo (false)

$status will be 0, because it reflects the result of echo, not false.

However, some commands do not modify status, such as switch. This allows us to determine whether the command succeeded:

switch (uname)
    case Linux
          echo "You're on Linux"
    case Darwin
           echo "You're OS X"
    case '*'
        if test $status = 0
             echo "You are on another system"
        else
             echo "uname failed"
        end
  end

Another change is that $status will reflect the value of a command substitution within a prior argument:

echo (false) $status (true) $status

This will now output "1 0", which matches the behavior of bash and zsh.

The most significant benefit of this is that it allows a "transparent set", as in #214:

if set path (which python)
    echo "Python is at $path"
else
    echo "Python is not installed"
end

Without this change, it is far more difficult to determine whether which failed.

This only affects command substitutions run by user code. Internal uses, such as fish_prompt, will not change the exit status.

@maxfl
Copy link
Contributor

maxfl commented Jan 28, 2013

Looks cool.
The only limitation I see is that it will be only helpful for the internal commands.
All the external commands which are used with command substitutions will override the status. But this is a minor issue. The benefits of this feature are going to cover most of the needs.

@ridiculousfish
Copy link
Member Author

Since there was no objections (or even much interest) I went ahead with this.
ad8d68d

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants