Skip to main content

Posts

Showing posts with the label printf

printf bash command

When writing a bash scripts most of us by default use echo command as means to print to standard output stream. echo is easy to use and mostly it fits our needs without any problem. However, with simplicity very often comes limitation. This is also the case with echo command. Formatting an echo command output can be a nightmare and very often impossible task to do. The solution to this can be a good old friend of all C/C++ the “printf” tool. printf can be just as easily implemented into a bash script is it is used with C/C++ programs. This article describes some basics of printf along with practical examples: Syntax printf accepts a FORMAT string and arguments in a following general form: # printf In format prinft can have format specifiers, escape sequences or ordinary characters. When it comes to arguments it is usually text we would like to print to standard output stream. Let’s start with something simple from a bash shell command line:    ...