What does the 0 2>&1 >/dev/null
below mean?
rawout=$(HandBrakeCLI -i /dev/dvd -t 0 2>&1 >/dev/null)
also below,
count=$(echo $rawout | grep -Eao "\\+ title [0-9]+:" | wc -l)
what does the -Eao "\\+ title [0-9]+:" | wc -l)
imply?
According to HandBreak cli documentation:
The -t 0
option means "scan all titles only".
Additionally, 2>&1 >/dev/null
is a linux terminal output redirection of your errors (error stream) to your outpus stream (which displays general command and output messages to the terminal), and both of them redirected to /dev/null
special device file wich discards whatever is sent to it.
It is a method of making a command silent and not show you any messages.
The expression grep -Eao "\\+ title [0-9]+:" | wc -l
is a combination of the output of grep -Eao "\\+ title [0-9]+:"
sent to the wc -l
command, which counts the number of lines in a file or a command output.
In other words: count how many lines the command grep -Eao "\\+ title [0-9]+:"
outputs.
More about wc
in the wc manpage.
The grep
util performs a search of a given expression pattern inside a file or a command output:
The -a
option means "handle this data given as text data".
The option -E
is a deprecated option of grep
which sometimes used to treat patterns as extended regex.
lastly, -o
means "show only matching results of a whole matching line".
Overall the use of grep
here seems to be a searching mechanism for an series title and episode, and display their name.
More about grep
in the grep manpage.
/dev/null
that's exactly what I wrote. As I also mentioned, it is a common way of silencing a program so it won't interfere any built in outputs or confuse the user when an OS command error occurs, while the author usually handles it themselves within the script.