-
Notifications
You must be signed in to change notification settings - Fork 152
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
Backticks nested in $( )
result in misdirected output
#478
Comments
Note that this bug exists in the |
By "the one that ships with RHEL 7" I mean |
@sckendall2 We have built current development version from the last beta release by changing the build system, reformatting code etc. @krader1961's comment means that this bug was not introduced by those changes. It helps us in narrowing down how the regression got introduced. |
@siteshwar Whoops, I didn't mean my comment as a response to @krader1961. I started my comment before his appeared. I was just clarifying my initial post. |
fwiw this works as expected:
ksh handles input output for $() and `` differently. We have seen multiple issues with each of these syntaxes in past. Unfortunately the code to handle input/output in subshells is too complicated and it's very likely that fixing each bug will create another regression. |
An effective workaround is forcing ksh93 to fork off the command substitution subshell in a separate process by including a dummy redirection in it:
|
Agreed. The backtick substitution syntax has been deprecated for more than two decades and has lots of quirks. So unless the fix is obviously correct (trivial would be even better) it's probably not going to happen. |
There was a regression introduced after the last stable release which causes mishandling of redirections in subshells. For e.g. foo=$(print `/bin/echo bar`) print foo=$foo prints `bar` on stdout and the variable foo is empty. Handling of redirections in $() style of command substitution was changed after the last stable release. sh_subshell() function replaces sfstdout with a newly created temporary stream with this line : sp->saveout = sfswap(sfstdout, NULL); The newly created stream has it's fd value set to -1. If `` style of command subtitution happens inside $(), it tries to use this stream with invalid fd and fails to close it. So redirections for stdout do not work. We should check if the stream that we are closing actually corresponds to the file descriptor that we want to close. If not, directly invoke close() on the fd. Resolves: #478
sfio provides an api to get file descritptor of a stream. Use it instead of directly accessing private member of Sfio_t struct. Related: #478
@sckendall2 I have merged a fix for this. If you want to use latest development version of |
ksh 93v- beta introduced a regression with nested command substitutions: backticks nested in $( ) result in misdirected output. This has never been in 93u+, but since we're often backporting things, let's avoid backporting this bug. It is also useful if this shows up when running our bin/shtests against the actual beta by adding a SHELL=... argument. Ref.: att#478 src/cmd/ksh93/tests/subshell.sh: - Add reproducer submitted by the reporter as a regression test.
In the following, either the /bin/echo command or the first print command must be sending their output directly to the script's stdout:
This bug is in the latest code, fetched earlier today. It's a regression from older versions of ksh93, such as the one that ships with RHEL 7.
The text was updated successfully, but these errors were encountered: