Disclaimer. This is thoroughly explained so my future self remember the whole thing when he comes back to the issue I'm about to give up upon for today.
This is gonna be useful for debugging install and *-deps steps of dot command. I want to show at the end of each step the log files of the topics that failed.
My idea is to grep only the log files that contain the name of the failed topic:
For grep to grep for several words the following syntax is used:
grep 'a\|b'
Now it should simply be about joining with \| the array errors containing the failed topics, but well, this is Shell, so it's not gonna be so easy, apparently. I first have to resolve to defining a custom function.
function join { local IFS="$1"; shift; echo "$*"; }
This allows me to join the $errors into a string with a separator:
$ echo `join \| ${errors[@]}`
homebrew|whatever
The problem is that there is no way to use \| as separator as IFS only takes the first character | (since \ in the command is used to escape |) and so I have to sed the result to replace | for \|:
$ echo `join \| ${errors[@]}` | sed 's/|/\\|/g'
homebrew\|whatever
So far so good... Let's story this in a variable so that it can be used as initially intended by `grep
error_topics=`join \| ${errors[@]} | sed 's/|/\\|/g'`
echo $error_topics
And the output is:
homebrew|whatever
And I couldn't find any way to store it correctly. :'(
Disclaimer. This is thoroughly explained so my future self remember the whole thing when he comes back to the issue I'm about to give up upon for today.
This is gonna be useful for debugging
install
and*-deps
steps ofdot
command. I want to show at the end of each step the log files of the topics that failed.My idea is to grep only the log files that contain the name of the failed topic:
For
grep
to grep for several words the following syntax is used:Now it should simply be about joining with
\|
the arrayerrors
containing the failed topics, but well, this is Shell, so it's not gonna be so easy, apparently. I first have to resolve to defining a custom function.This allows me to join the $errors into a string with a separator:
The problem is that there is no way to use
\|
as separator asIFS
only takes the first character|
(since\
in the command is used to escape|
) and so I have tosed
the result to replace|
for\|
:So far so good... Let's story this in a variable so that it can be used as initially intended by `grep
And the output is:
And I couldn't find any way to store it correctly. :'(