Examples of Bash Printf Command
Here you will find out:
- about bash printf command and its syntax
- about special printf characters and their meanings
- what examples of using a bash printf function are
- when DiskInternals can help you
Are you ready? Let's read!
What is a bash printf command?
This is the built-in bash command for formatted output. The printf commands replaces the familiar echo command, which is limited in its capabilities. In addition, different versions of Unix have had different versions of it, which leads to incompatibilities. This property often forces you to use the newer printf command.
Information about syntax of shell script printf
Keep in mind that older versions of bash do not always support the printf command. The printf command prints an argument to standard output, using a specific format.
The general syntax is as follows:
Here is a bash printf example of its construction:
Where "Last name: %s\nName: %s\n" is in TeX format and two variables are passed as arguments pointed to by %s in the formats line (1 format specifier printf = 1 argument).
The structure of format string
All the components of a format string can be divided into 3 parts:
- ordinary characters for subsequent direct output
- several consecutive characters, often indicated by a character /
- format specifications to express the next argument
Special printf characters and their meanings
Each such character has its own special purpose and is interpreted only in the format %b:
- \c - End the output in the same way as escaping \c as in echo -e.
- The characters \', \" and \? are not deleted.
- All octal numbers starting with \0 can hold up to four digits.
Examples of using a bash printf function
There are various ways to use the bash printf function. The most common bash printf examples are mentioned here:
- If you need to print some text, you need to quote it; for example,

- If you want to avoid external lines for this line, use %s; for example,

- If you want to enter not one, but several parameters for printing according to the principle of the cylinder, this can be done; for example, like this:

- If you need to enter an integer value (for example age), then you can do it with %d; for example,

As you can see, this command has a lot of possibilities, and, if you delve deeper into this issue, it will become even more interesting.
Try to open Linux files from Windows
Here we are talking about the professional-quality and unique DiskInternals Linux Reader. You need to use it if you are using a virtual machine or dual-boot setup, and you need to get files from Linux to Windows. You just need to install this application once and don’t worry about transferring data from one OS to another. The program works with most file systems: Ext2/3/4, ReiserF, Reiser4, HFS, HFS +, FAT, exFAT, NTFS, ReFS, UFS2, and ZFS, XFS, Hikvision NAS and DVR (preview only).




DiskInternals Linux Reader transfers files using the Wizard and this is done at no cost. There is read-only access to files on Linux disks, leaving the source files unchanged, which indicates the precautions taken. In addition, before transferring data, you can preview and make sure of the results. Perhaps the most pleasant bonus is the function of creating a disk image, also for free. Therefore, DiskInternals Linux Reader should be your desktop application and reliable assistant.
Related articles
- About a bash date command
- How to Access Linux Ext2 or Ext3 on Windows
- How to Access Ext4 from Windows
- How to Mount Ext4 on Windows for Free
- Mount Linux Drive on Windows for Free
- Bash Script: All You Need to Know
- An Algorithm: How to Create Bash While Loop
- Linux Shell: What You Need to Know at First
- 5 Basic Shell Script Examples for Your First Script
- Bash: How to Check if the File Does Not Exist
- Bash Time Command on Linux
- How to use bash get script directory in Linux
- How to Check Bash String Equality
- How to Use Linux Wait Command
- Bash: How to Loop Through Files in Directory
- 20 Examples of Bash Find Command
- Bash Cat Command in Examples
- Bash Script SSH: How to Use It
- Bash: A Script For User Input
- Linux ZSH: the basic you need to know
- Basic of Grep in Linux Shell Script
- Shell Script Cut: Basic You Need to Know
- Bash: How to Check if String Not Empty in Linux
- Bash: how to split strings in Linux
- Linux: Sudo in Bash Scripts
- Hello World Script in Bash
- A Linux bin/bash Shell
- Linux: New Line in Shell Script
- Linux: Bash String Ends With
- Linux: Bash First Line
- Linux: $0 in a Shell Script
- Linux: A Bash Startup Script
- Linux: Write a Shell Script
- Shell Script: Replace String in File
- A crontab service shell script
- Bash and sh: is there any difference
- A Bash Dirname Command
- Linux: A Bash Source Command
- A Bash to Loop through Lines in File
- Linux: A Bash Linter
- A Bash Nested Loop
- A Bash Test Command
- Use a Shell Script to Send an Email
- A Bash Status of Last Command
- Linux: A Bash Basename Command
- Using Bash to Write to a File
- About Bash Language
- Bash for Loop in One Line
- AWK in a Bash Script
- Learn about useful bash scripts
- Learn about systemd startup script
- About chaining bash commands
- Learn about a bash error code
- Using a bash tee command
- About a bash export command
- Learn about a bash wait command
- Arch Linux install script
- About advanced bash scripting
- To run a shell script in Dockerfile
- About a bash UNTIL loop
- Learn about C shell script
- Learn about Korn shell scripting
- Using /usr/bin/env command
- Whether bash waits for command to finish
- Using bash if 0
- Using && in an IF statement in bash
- If you want to run shell script in background
- The disk you inserted was not readable by this computer error
- Learn about SFTP in bash scripting
- Learn to run Perl script in Linux
- Examples of using the Expect
- Copy command in shell scripts
- Shell script usage
- Install Oracle Database
- Here is everything you need to know about Bash for Windows
- Guide in Pictures
- How to Use Shell Script Sleep Command
- A Bash Multiline Command
