1

The command mvn -version outputs the first line in bold.

$ mvn -version
Apache Maven 3.6.0  # Bold text
Maven home: /usr/share/maven
Java version: 1.8.0_242, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-1058-aws", arch: "amd64", family: "unix"

How can I unbold this line and write only that line to output? E.g.:

$ mvn -version | head -n1 | xargs echo -E
Apache Maven 3.6.0  # Still bold

A simpler example:

echo -e "Normal \e[1mBold \e[0mand Normal" | xargs echo -E

outputs "Normal Bold and Normal"

How can the resulting text be "unbolded"?

Bash version: 4.4.20

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
  • Why use `xargs` at all? And note that `echo -E` is nonstandard functionality -- in some modes, bash won't honor it at all except as instruction to print `-E`. (Same is true of `echo -e`, for that matter). – Charles Duffy Feb 13 '20 at 15:40
  • My interpretation of the `-E` flag was wrong, so yeah, it doesn't make sense here – Brad Solomon Feb 13 '20 at 15:41
  • *nod* -- all it does is prevent further backslash-escape sequences from being honored, but by the time they're already converted to terminal control sequences, there aren't any backslash-escape sequences left. – Charles Duffy Feb 13 '20 at 15:41
  • ...so, this smells to me like a duplicate of [How to script ANSI escape sequences from a variable](https://stackoverflow.com/questions/23416278/how-to-strip-ansi-escape-sequences-from-a-variable), or -- more loosely -- [How to remove `^[`, and all of the escape sequences in a file using linux shell scripting](https://stackoverflow.com/questions/6534556/how-to-remove-and-all-of-the-escape-sequences-in-a-file-using-linux-shell-sc). – Charles Duffy Feb 13 '20 at 15:42
  • Probably also dup of https://superuser.com/a/380778/992125, e.g. `mvn -version | head -n1 | sed 's/\x1b\[[0-9;]*m//g'` – Brad Solomon Feb 13 '20 at 15:43
  • https://stackoverflow.com/questions/2924697/how-does-one-output-bold-text-in-bash Something like this ? – abhishek phukan Feb 13 '20 at 15:43
  • 1
    @abhishekphukan, opposite of that, the OP wants to *not* output bold text but convert it to be plain even though what they read as input has control sequences telling the terminal to make it bold. – Charles Duffy Feb 13 '20 at 15:44
  • 2
    A better duplicate is the following, which says to use `mvn -B` to suppress highlighting https://stackoverflow.com/questions/43638595/how-do-i-remove-colors-from-maven-output – Jon Feb 13 '20 at 15:48
  • `mvn -B -version` still outputs bold @Jon – Brad Solomon Feb 13 '20 at 15:52

0 Answers0