Skip to content

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

Closed
@lilyball

Description

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)

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