Skip to content
TheChatArchiveThe Chat Archive
Metallama-4-maverick-03-26-experimental· MetaHugging Face LMArena Human Preference 140K

print the test "directories" with bold and underline style in bash.

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Coherecommand-a-03-2025’s answer.
  1. User

    print the test "directories" with bold and underline style in bash.

  2. Meta Assistant

    A nice formatting question!

    To print text with bold and underline style in Bash, you can use ANSI escape codes. Here's the magic incantation:

    echo -e "\033[1;4mDirectories\033[0m"
    

    Let's break it down:

    • echo -e: The -e option enables interpretation of backslash escapes, which we need for the ANSI codes.
    • \033[: This is the ESC (Escape) character, which starts the ANSI sequence. You can also use \e[ instead of \033[, both work.
    • 1;4m: This is where the magic happens:
      • 1 means bold (or bright, depending on the terminal). You can also use 2 for faint (dim).
      • 4 means underline. Other options include 5 for blinking and 7 for inverse (reversed colors).
      • m is the character that marks the end of the ANSI sequence. Think of it as "apply these styles".
    • Directories: The actual text we want to print, now formatted with bold and underline.
    • \033[0m: This resets the text style back to default. The 0 means "reset all styles". If you omit this, the bold+underline style will "leak" to subsequent prints!

    Here's a brief illustration of other styles:

    echo -e "\033[1mBold\033[0m"       # only bold
    echo -e "\033[4mUnderline\033[0m"  # only underline
    echo -e "\033[7mInverse\033[0m"    # inverse (swapped fg/bg colors)
    echo -e "\033[31mRed\033[0m"       # red color (31 is red fg, 41 would be red bg)
    

    If you want to make it more readable, you can define a function:

    print_bold_underline() {
      echo -e "\033[1;4m$1\033[0m"
    }
    
    print_bold_underline "Directories"
    

    Voilà! Your "Directories" text should now proudly display with bold and underline style.

    Tips:

    • Not all terminals support all ANSI styles (e.g., some ignore underline or blinking). Test on your target environment!
    • If you're writing a script, consider adding a check for [[ $- == *i* ]] (interactive shell) before using fancy formatting, as non-interactive shells might not interpret ANSI codes correctly.
    • For more advanced terminal control, explore tput commands, like tput bold or tput setaf 1 (for red color).

    Happy formatting!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.