Skip to content

Command substitution loses stdout after nested function redirects stdout to /dev/null #951

@vmihalko

Description

@vmihalko

Summary

When executing a function in a subshell: the output is lost when a previous line in the function redirects to stderr while not having any output.

Minimal reproducer

#!/usr/bin/ksh
function echo_devnull {
	echo "DEVNULL" >/dev/null
}
function func {
	echo_devnull >&2
	echo "FUNC"
}
OUT=$(func)
echo "OUT: ${OUT}"

Expected: OUT: FUNC
Actual: OUT: (empty)

In OUT=$(func), output from func is lost when a prior line in func runs the customer pattern echo_devnull >&2 (redirect that call’s stdout to stderr) and echo_devnull itself sends stdout to /dev/null. The following echo "FUNC" should appear in OUT but OUT is empty. bash is OK.

Reproduced on dev 4c391d.

Notes

Downstream indicated behaviour was OK on ksh-1.0.0~beta.1 and fails on current 1.0.6 / 1.0.10 version

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockerThis had better be fixed before releasingbugSomething is not working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions