Skip to content

No reasonable equivalent for bash's if foo="$(some command)" #158

Closed

Description

@lilyball

In bash, if I write

if foo="$(some command)"; then

then the if statement will actually conditionalize based on the exit status of $(some command). I don't see any way to get the equivalent functionality in fish. The fundamental problem is variable assignment in fish must be done via the set command, which overwrites $status, and so there is no reasonable way to capture the output of a command and its return value separately. The only unreasonable way I can think of looks like

set -l oldstatus
set -l foo (some command; set oldstatus $status)

Activity

  1. ridiculousfish commented on Mar 12, 2013

    @ridiculousfish
    Member

    This was fixed in #214; now you can write if set foo (somecommand) and, set will fail if either the subcommand failed, or if setting the variable itself failed.

  2. locked as resolved and limited conversation to collaborators on Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions