0
0
Bash Scriptingscripting~5 mins

Color output (ANSI escape codes) in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are ANSI escape codes used for in bash scripting?
ANSI escape codes are special sequences that control text formatting, color, and other output options in the terminal.
Click to reveal answer
beginner
How do you print red colored text in bash using ANSI escape codes?
Use the code \033[31m before the text and \033[0m after to reset color. Example: echo -e "\033[31mRed Text\033[0m"
Click to reveal answer
beginner
What does the ANSI escape code \033[0m do?
It resets all text formatting and colors back to the terminal's default settings.
Click to reveal answer
beginner
Name three common text colors you can use with ANSI escape codes.
Red (31), Green (32), Yellow (33) are common colors used in ANSI escape codes.
Click to reveal answer
beginner
Why is it important to reset color after printing colored text in bash?
If you don't reset, the terminal will keep using the color for all following text, which can cause confusion or messy output.
Click to reveal answer
Which ANSI escape code sets the text color to green?
A\033[31m
B\033[32m
C\033[33m
D\033[0m
What does the escape sequence \033[0m do?
ASets text to bold
BClears the screen
CSets text color to blue
DResets all text formatting
How do you enable interpretation of backslash escapes in echo command?
Aecho -n
Becho -E
Cecho -e
Decho --escape
Which color code corresponds to yellow text in ANSI escape codes?
A33
B34
C31
D35
What happens if you forget to reset color after colored output?
AText color stays changed for following output
BTerminal crashes
CText becomes invisible
DNothing happens
Explain how to print colored text in bash using ANSI escape codes.
Think about how to start color, print text, then reset.
You got /3 concepts.
    List three common ANSI color codes and their colors.
    Remember the basic colors used in terminal output.
    You got /3 concepts.