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 output with printf - Bash Tutorial
From the course: Learning Bash Scripting
Formatting output with printf
- [Narrator] As we've seen with echo composing strings that include variables or other data can get a little bit tedious, and so I want to show you another way to do it. The printf builtin gives us the ability to use placeholders when we compose strings and format values in ways that can make our script and our output look cleaner and more organized. Let's compare getting the same output result with both echo and printf. Both of these statements print "The results are: four and three." Using printf, we'll write the literal parts of our string, the parts that don't change, and instead of putting Bash code mixed in with the string we use a placeholder wherever a dynamic value, one that will be the result of something our script runs will go and then at the end of the line we'll put whatever code we'll provide those values in the same sequence we used for the placeholders. If we provide more values than there are placeholders…
Contents
-
-
-
-
Understanding Bash script syntax5m 18s
-
(Locked)
Choosing a text editor for Bash scripting1m 33s
-
(Locked)
Displaying text with "echo"4m 26s
-
(Locked)
Working with variables5m 21s
-
(Locked)
Working with numbers8m 44s
-
(Locked)
Comparing values with test4m 59s
-
(Locked)
Comparing values with extended test3m 34s
-
(Locked)
Formatting and styling text output8m 13s
-
(Locked)
Formatting output with printf5m 6s
-
(Locked)
Working with arrays4m 25s
-
(Locked)
Challenge: Make a script that generates a system report1m 1s
-
(Locked)
Solution: Make a script that generates a system report1m 26s
-
-
-
-
-