jhsu802701 wrote: Wed Nov 09, 2022 9:46 pm
I'm having difficulty making sense of the following line of code:
Code: Select all
main_case 7>&1 1>&2 2>&7 \
| tee -a $err_file | sed -e "s/^/$red/" -e "s/$/$nc/"
More specifically, I'm having difficulty making sense of the portion of the first line after "main_case" and before the backslash.
The first line "swap"'s or toggles stderr with stdout:
A nice attempt to explain what it does is made by our mastermind
@BitJam himself (found within the live init) with this picture:
Code: Select all
# Evaluate redirects RIGHT TO LEFT:
#
# stdout 1 -------. .---> while, sed, tee ---> screen (stdout)
# \ /
# stderr 2 ---. `--- / -------------------------> screen (stderr)
# \ /
# 7 `------'
So after the switch was done, the "old" stderr (2) is now the new stdout and can be processed with tee and sed,
which in this case is done in order to send "old" stderr to a log-file and and colorize the tee-duplicated error-lines send to the screen.
jhsu802701 wrote: Wed Nov 09, 2022 9:46 pm
I understand in general that any errors in the screen output are directed to the error file ($err_file). I understand in general that the numbers and symbols of the part of the code in question specify details of how the screen output is redirected.
However, I'm having difficulty finding a good reference on any specifics of what it all means. It's not a normal command like "tee" or "sed".
Hmm.., that's normal shell file descriptor handling ... ( admitally for the advanced use case)
jhsu802701 wrote: Wed Nov 09, 2022 9:46 pm
In case you're wondering, what I'd like to do is execute the main_case function differently in the GitHub Workflows environment. My plan is to use an if statement to print the error information on the screen (as well as in the file) in the GitHub Workflows environment. (I've already made changes to the code that apply ONLY in the GitHub Workflows environment.)
OK, I must admit I have never used "GitHub Workflows", so in this respect not really sure what you are talking about.
But the above file descriptor "switch" magic combined with tee and sed, does already what you want to do:
"to print the error information on the screen (as well as in the file)".
So I'm not sure what you are looking for, but this might be simply related about, that I'm having no knowledge of "GitHub Workflows". (May be you give us a quick introduction of how to use it and what it is good for.)
Thanks