4 ms·
Well you can use arbitrary file descriptors to get things out of a subshell, not just stdout. I had to do it when I had to get something out of band, while redi
by gpderetta 5y ago
Well you can use arbitrary file descriptors to get things out of a subshell, not just stdout. I had to do it when I had to get something out of band, while redirecting stdout through a pipeline.
Mind, if possible, it is even uglier than using stdout.
- cryptonector 5y agoFew people know about `{varname}` I/O redirection...
- gpderetta 5y agoYes. The fact that shell scripting is both so powerful and yet such an ugly language is painful.
- Groxx 5y agoyeah, I was wondering if there was some reason that something like this wouldn't work: err_f="$(mktemp)" third_f="$(mktemp)" out="$(cmd 2>"$err_f" 3>"$third_f")" err="$(cat "$err_f")" third="$(cat "$third_f")" Seems like that should work fine, and it's not even that odd looking or hard to understand. But I haven't tried, not sure if there's some surprise lurking in the depths of tempfiles or something.
- gpderetta 5y agoNormally I use mkfifo then immediately rm it after opening the file with exec. The fact that there isn't a good way to open an anonymous pipe and get its two file descriptors in bash is very annoying.