Bash Printf Function Tutorial with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/bash-printf-function-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Bash provides programming features to make Linux system administrator’s life easier. printf is one of the most used function used by Linux bash programmers. In this tutorial we will look Linux bash printf features and use cases while developing bash programs. Bash printf function is very similar to the C printf function.

Print

We can use printf function easily by providing the text in double quotes. In this example we will print Hello Poftut .

Print Given Text

We can provide  parameters to print text. We will use %s as text specifier in printf function.

This will print

Print Multiple Given Text

We can also provide multiple parameters to the printf  command. In this example we will print to the Poftut , ismail ,ahmet .

This will print

Print Integer Numbers

We can also print integer type values with bash printf function. We will use %d to print integer values. In this example we will print the age variable.

This will print

Print Float Numbers

We can print float type values with bash printf function too. We will use %f to print float values. In this example we will print the price variable.

LEARN MORE  Bash Sleep In Linux

This will print

Format Specifiers

We can use format specifiers to print given text or numeric values. We will can specify the floating point decimal part and floating point part with . . In this example we will print only 2 numbers from floating point parts.

This will print

Justify Left

We may need to align the given text to the left. In this situation we will use - to justify left.

This will print

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/bash-printf-function-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.