From the course: Learning Bash Scripting
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Formatting and styling text output - Bash Tutorial
From the course: Learning Bash Scripting
Formatting and styling text output
Let's move back to working with text for a while. One option offered by the echo built-in is -e, which tells Bash to interpret escaped characters or sequences, which can be used to enhance text output. Escaped sequences can represent special characters like Tab, Newline, or the Bell. And they can be used to change the color of text in the terminal as well. When we write scripts, we'll often want to format text to line it up in columns or indent it. And the tab character plays a role there. For example, I can make some column headers with tabs between them and then provide another line with the same number of tabs. I'll write echo -e "Name\t\t, for two tab characters, and number. I'll write a semicolon, and I'll write another echo statement here. echo -e, my name, two tab characters, and 123. I'll run this. And because of the tab characters, my text lines up in easy-to-see columns. Another special character, the newline character, tells the terminal to start putting the following text…
Contents
-
-
-
-
(Locked)
Understanding Bash script syntax7m 24s
-
(Locked)
Displaying text with "echo"5m 8s
-
(Locked)
Working with variables6m 19s
-
(Locked)
Working with numbers10m 2s
-
Comparing values with test7m 6s
-
(Locked)
Comparing values with extended test5m 43s
-
(Locked)
Formatting and styling text output8m 38s
-
(Locked)
Formatting output with printf5m 33s
-
(Locked)
Working with arrays5m 10s
-
(Locked)
Challenge: Make a script that generates a system report1m 10s
-
(Locked)
Solution: Make a script that generates a system report2m 48s
-
(Locked)
-
-
-
-