Your first Bash command
Print a line of text
A command tells the shell to do something. printf is a Bash built-in: Bash can run it without launching an external executable. It formats and writes text to standard output, normally displayed in your terminal. Use the following fixed format for an ordinary line of text.
Expected output when executed:
Hello, Bash!The first argument is the format. %s means insert a string, and \n in this format means a newline. The second argument is the text to insert. Single quotes keep the enclosed characters literal for Bash; printf itself interprets the format. The quotes are not part of the printed text.
Print more than one line
Expected output when executed:
Task startedTask finishedThere are two text arguments. With this format, printf reuses the format for the second text argument and prints one line per argument. Change the messages to practice without changing the format.
Keep text separate from the format
Expected output when executed:
Progress: 50%A percent sign inside the text argument is printed literally. If you put arbitrary text directly in the format position, percent signs and backslash escapes may be interpreted. Keeping the format fixed makes the result predictable. Avoid using arbitrary user text as a format string.
Practice
Print two lines: Build started and Build complete. Then print 100% ready using the same fixed format.
Next lesson: Commands, options and arguments