The simplest way to print in Linux command line is by using echo command.
However echo command won8217t be adequate when you need to print formatted output.
This is where printf command helps you. The bash printf command operates like the printf command in CC programming language.
Can you guess the output.
The first argument s expects a string d expects a decimal integer just like CC. Don8217t worry if you are not familiar with CC. .
You don8217t need to learn it just for using printf command in your Bash scripts. Let me show you some examples of Bash printf command.
Let8217s start with the syntax first.
Here format is a string that determines how the subsequent values will be displayed.
In the example printf My brother s is d years old.n Prakash 21 the entire 8220My brother s is d years old.n8221 is format and it is followed by the arguments Prakash and 21. The arguments are used for replacing the format specifiers s d etc which I8217ll explain later in this article.