0

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?

0

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.

6
  • Thank You Pizza. Much appreciated.
    – Babek
    Mar 15 '21 at 7:03
  • However, I think "2>&1 >/dev/null" is redirecting the errors to the terminal and the output to the null!! At least that what I understood when I did a bit of research. What puzzles me is WHY? rawout=$(HandBrakeCLI -i /dev/dvd -t 0 2>&1 >/dev/null) ; count=$(echo $rawout | grep -Eao "\\+ title [0-9]+:" | wc -l); This script is trying to enumerate the number of episodes in a disc. FYI
    – Babek
    Mar 15 '21 at 7:13
  • @Babek Yes, regarding /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.
    – Pizza
    Mar 15 '21 at 8:27
  • If my answer helped you, feel free to mark it as accepted (The V button) so it won't appear as "Unanswered", and you are more than welcome to upvote it if it was clear enough to understand.
    – Pizza
    Mar 15 '21 at 8:29
  • Thanks. How do I mark it as accepted??? sorry no idea
    – Babek
    Mar 17 '21 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.