Using Bash printf Command for Printing Formatted Outputs

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.

...

Read Full Post

News Link: https://linuxhandbook.com/bash-printf/.
RSS Link: https://linuxhandbook.com/feed/.

Linux Chatter is a news aggregator service that curates some of the best Linux, Cloud, Technical Guides, Hardware and Security news. We display just enough content from the original post to spark your interest. If you like the topic, then click on the 'read full post' button to visit the author's website. Use Linux Chatter to find content from amazing authors!

Note: The content provided has been modified and is not displayed as intended by the author. Any trademarks, copyrights and rights remain with the source.

Disclaimer: Linux Chatter sources content from RSS feeds and personal content submissions. The views and opinions expressed in these articles are those of the authors and do not necessarily reflect those of Linux Chatter.