diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 8735a6b2c..179d71d30 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -1401,8 +1401,8 @@ int sh_exec(register const Shnode_t *t, int flags) sh_unscope(shp); bp->ptr = (void*)save_ptr; bp->data = (void*)save_data; - /* don't restore for subshell exec */ - if((shp->topfd>topfd) && !(shp->subshell && np==SYSEXEC)) + /* don't restore for 'exec' or 'redirect' in subshell */ + if((shp->topfd>topfd) && !(shp->subshell && (np==SYSEXEC || np==SYSREDIR))) sh_iorestore(shp,topfd,jmpval); shp->redir0 = 0; diff --git a/src/cmd/ksh93/tests/io.sh b/src/cmd/ksh93/tests/io.sh index 01fc8d4bc..0b0052653 100755 --- a/src/cmd/ksh93/tests/io.sh +++ b/src/cmd/ksh93/tests/io.sh @@ -698,8 +698,13 @@ got=$(export tmp; "$SHELL" -ec \ # ====== # Redirections of the form {varname}>file stopped working if brace expansion was turned off -redirect {v}>$tmp/v.out; echo ok >&$v -[[ $(<$tmp/v.out) == ok ]] || err_exit '{varname}>file not working with brace expansion turned off' +set +B +{ redirect {v}>$tmp/v.out && echo ok >&$v; } 2>/dev/null +set -B +[[ -r $tmp/v.out && $(<$tmp/v.out) == ok ]] || err_exit '{varname}>file not working with brace expansion turned off' +# ...and they didn't work in subshells: https://github.com/ksh93/ksh/issues/167 +(redirect {v}>$tmp/v.out; echo ok2 >&$v) 2>/dev/null +[[ -r $tmp/v.out && $(<$tmp/v.out) == ok2 ]] || err_exit 'redirect {varname}>file not working in a subshell' # ====== exit $((Errors<125?Errors:125))