echo always exits with a 0 status, and simply prints arguments followed by an end of line character on the standard output, while printf allows for definition of a formatting string and gives a non-zero exit status code upon failure. The computer being used for this test is a 650mHz AMD Athlon with 512mb RAM running Mandrake Linux … Does printf send an extra EOF at the end of its output? printf was introduced with the Ninth Edition System (reference in SUSv3). Basically, it's a portability (and reliability) issue. Generating Output With echo command. Some have a -E to disable escape sequences, some have -n but not -e, the list of escape sequences supported by one echo implementation is not necessarily the same as supported by another. echo "Hello World" printf, on the other hand is more reliable, at least when it's limited to the basic usage of echo. Use printf (1) instead, if you need more than plain text. Note that in POSIX mode, bash is still not POSIX conformant as it doesn't output -e in: The default values for xpg_echo and posix can be defined at compilation time with the --enable-xpg-echo-default and --enable-strict-posix-default options to the configure script. I have heard that printf is better than echo. Now when a standard UNIX echo receives an argument which contains the two characters \ and t, instead of outputting them, it outputs a tab character. One "advantage", if you want to call it that, would be that you don't have to tell it like echo to interpret certain escape sequences such as \n. A reliable way of printing a string is printf %s "$string". To print a double quote, enclose it within single … (Though it will work OK with some (non UNIX compliant) echo implementations like bash's when the xpg_echo option has not been enabled in one way or another like at compilation time or via the environment). There's a core of features that is specified by POSIX, but then there are a lot of extensions. Speed of echo vs print in PHP . On those echo implementations that support options, there's generally no support of a -- to mark the end of options (the echo builtin of some non-Bourne-like shells do, and zsh supports - for that though), so for instance, it's difficult to output "-n" with echo in many shells. Additionally, functions can be called anytime and repeatedly, this allows you reuse, optimize and minimi… The phrase "if you want to call it that" implies pretty strongly that you think it isn't. Here is probably the best description of echo vs printf, http://www.in-ulm.de/~mascheck/various/echo+printf/. Why the scare quotes? The behavior varies for printf '%10s\n' "$var" in multi-byte locales, there are at least three different outcomes for printf %b '\123'. Strictly speaking, you could also count that FreeBSD/macOS /bin/echo above (not their shell's echo builtin) where zsh's echo -E - "$var" or yash's ECHO_STYLE=raw echo "$var" (printf '%s\n' "$var") could be written: And zsh's echo -nE - "$var" (printf %s "$var") could be written. No Unix/Linux implementation/distribution in their right mind would typically do that for /bin/bash though. echo is faster on my side (bash 4.3.46). Echo and print are perhaps one of the most interchanged PHP output. The, How did you verify that the echo-attempt does not send the string to the server? I had to use prinf to be able to print the literal string "-e". So two bash echos, even from the same version of bash are not guaranteed to behave the same. did not send the "blah" command to the server listening on 8125, whereas. Is this a difference in bash versions, or do these uses differ somehow? Even if you're already familiar with the printf command, if you got your information via "man printf" you may be missing a couple of useful features that are provided by bash's built-in version of the standard printf(1) command.. It means their purpose is same , to display something to standard output. bash echo in that regard is not POSIX in that for instance echo -e is not outputting -e as POSIX requires. posix mode can be enabled if bash is called as sh or if POSIXLY_CORRECT is in the environment or with the the posix option: xpg_echo expands sequences as UNIX requires: This time, bash is both POSIX and UNIX conformant. One downside of printf is performance because the built-in shell echo is much faster. For instance, you'd do builtin getconf; getconf UNIVERSE = att to change the UNIVERSE setting to att (causing echo to behave the SysV way among other things). Echo vs Print. https://unix.stackexchange.com/questions/58310/difference-between-printf-and-echo-in-bash/77564#77564, Couldn't verify the performance tests. This video also discuss about their differences. In the first argument, all characters except two are interpreted literally: % starts a printf specifier, and \ starts an escape sequence (e.g. echo always exits with a 0 status, and simply prints arguments followed by an end of line character on the standard output, while printf allows for definition of a formatting string and … The proper way would be to monitor, https://unix.stackexchange.com/questions/58310/difference-between-printf-and-echo-in-bash/58312#58312. The handling of -e was added to ksh93's echo when in the BSD universe in the ksh93r version released in 2006 and can be disabled at compilation time. For most uses, printf is preferable. (But even if command 5 is an echo, command 6 still will be traced.) Syntax : echo [option] [string] But testing them with time (also built-in) the results say otherwise: Telling printf to add newline characters, just as echo does by default: that is obviously slower than without printing the \n, but yet faster than echo. Could you expand on that? Each function needs to be called by a main routine in order to run, thus, it is isolated with other parts of your code and this creates an easy way of code testing. Why wouldn't it be an advantage? 2021 Stack Exchange, Inc. user contributions under cc by-sa, https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/65819#65819, A lot of early unix development happened in isolation, and good software engineering principles like, As a note, the one (and maybe only) advantage of having. For trivial messages (no escape sequences, no options), echo is fine. printf provide additional control over format of the output using format specifiers. That's typically what recent versions of OS/X do to build their /bin/sh. Its roots are in the C programming language, which uses a functionby the same name. With multiple arguments, they are separated by spaces. (NB: the last \n is necessary, echo implies it, unless you give the -n option). On some shells like bash¹ or ksh93² or yash ($ECHO_STYLE variable), the behaviour even depends on how the shell was compiled or the environment (GNU echo's behaviour will also change if $POSIXLY_CORRECT is in the environment and with the version4, zsh's with its bsd_echo option, some pdksh-based with their posix option or whether they're called as sh or not). But apparently, there are other differences, and I would like to inquire what they are as well as if there are specific cases when to use one vs the other. POSIX says: if the first argument is -n or any argument contains backslashes, then the behaviour is unspecified. Concerning performance, I always had in mind that echo was faster than printf because the later has to read the string and format it. There is no way to "send" an EOF. It was added to more widely distributed Unix flavours with 4.3BSD-Reno and with SVR4. Even some certified systems like macOS5 are not compliant. echo is not portable when printing variable values, as it accepts options in them. It's not; echo has never behaved this way. Easy and basic tutorial of PHP showing how user can print output via echo print and printf. file=$(echo "$var" | tr ' ' _) is not OK in most implementations (exceptions being yash with ECHO_STYLE=raw (with the caveat that yash's variables can't hold arbitrary sequences of bytes so not arbitrary file names) and zsh's echo -E - "$var"6). Will output the content of $var followed by a newline character regardless of what character it may contain. All in all, you don't know what echo "$var" will output unless you can make sure that $var doesn't contain backslash characters and doesn't start with -. behave the same regardless of the OS) and allows much better formatting, being designed from the same name C function. And, item 3 within the array points to "Apr" (remember: the first index in an array in Bash is [0]). printf '%s\n' "$var". The POSIX specification actually does tell us to use printf instead in that case. Because different shells work differently, echo "$string" does not always print the specified string plus a newline. Bash Performance Test - Regex vs If/Else. But remember the first argument is the format, so shouldn't contain variable/uncontrolled data. In your case, assuming that blah doesn't start with a - or contain % or \, the only difference between the two commands is that echo adds a newline and printf doesn't. sent the data. This means that you must escape the percent symbol when not talking about format (%%). The formatting strings are described in the manual page for sprintf. (shebang) command 1 command 2 command 3 set -x command 4 command 5 command 6 set +x command 7 command 8 command 9 and Commands 4, 5, and 6 will be traced — unless one of them is an echo, in which case it will be executed but not traced. Recommended for you A builtin is a command contained within the Bash tool set, literally built in.This is either for performance reasons -- builtins execute faster than external commands, which usually require forking off [1] a separate process -- or because a particular builtin needs direct access to the shell internals. Now, someone thought it would be nice if we could do things like echo "\n\t" to output newline or tab characters, or have an option not to output the trailing newline character. https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/159115#159115, But many of those printf implementations are broken. It allows programmers to break a complicated and lengthy code to small sections which can be called whenever needed. Using one over the other is not likely to yield any performance improvement in your application. echo [option(s)][string(s)] Now, we shall see the different ways in which we can output the text on the terminal. Interpreting a variable as its value is one way of expanding it, but there are a few more you can leverage. :-/, Same thing, echo is faster (GNU bash, version 4.3.33(1)-release). The echo utility has been universally available for more than 4 … The difference is that echo sends a newline at the end of its output. "print", on the other hand, is a non-standard feature of ksh. When I changed my echo-heavy program from using /bin/echo to the shell's echo the performance almost doubled. Those specifications don't really come to the rescue here given that many implementations are not compliant. The two functions vprintf and vsprintf operate as printf and sprintf, but accept a format string and an array of values, instead of individual variables. GitHub Gist: instantly share code, notes, and snippets. If you want to literally print the string "-e", you will have difficulties doing it with echo. If I replace echo with printf, will it introduce any side effects (because of the >&2)? Echo. To print a new line we need to supply printf with format string with escape sequence \n ( new line ): $ printf "%s\n" "hello printf" hello printf The format string is applied to each argument: $ printf "%s\n" "hello printf" "in" "bash script" hello printf in bash script Format specifiers Display a line of text containing a double quote. These two commands which are mainly used to place output information to the visitor’s screen, such as like in the web page give the same action. The -e option will cause echo to search for escape characters in the string and execute them. (Some shells provide extensions that supply additional conversion specifiers.) Your wording implies that it isn't necessarily a real advantage. \n for a newline character). It offers no formatting option. The printf utility has been almost universally available for more than 2 decades and is a built-in in almost all current shells. Theoretically, echo is more efficient because it does not return any value. printf can basically do what the C version of it can do. For instance, some support a %q to quote the arguments but how it's done varies from shell to shell, some support \uxxxx for unicode characters. To output any string or number or text on the terminal, type the following command and press enter. All it was doing was outputting its arguments separated by a space character and terminated by a newline character. Benchmarks First, some background. According to the Linux documentation, the following is the syntax for echo command. echo vs printf January 12, 2019 January 12, 2019 jack4it In bash, or generally the family of shell languages, echo and printf are often used to output messages to the screen (or terminal, or tty, or stdout, to earn a few more geek points…). A more reliable echo can be implemented using printf, like: The subshell (which implies spawning an extra process in most shell implementations) can be avoided using local IFS with many shells, or by writing it like: With bash, at run time, there are two things that control the behaviour of echo (beside enable -n echo or redefining echo as a function or alias): echo prints its argument followed by a newline. You might want to use printf for its formatting options. https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/65807#65807, https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/65808#65808. Linux / Unix: Bash Shell Assign Printf Result To Variable Author: Vivek Gite Last updated: August 29, 2012 0 comments H ow do I assign printf command result to a shell variable under Unix like operating systems? The configuration is meant to be done via the (undocumented) astgetconf() API. At the end of the day it's a matter of taste and requirements what you use: echo or printf. After doing that, you'll notice the $_AST_FEATURES environment variable contains UNIVERSE = att. If you want to add a link outside your editor, you’ll need to code it into a custom function or add it directly in a theme file. That /bin/echo is the one from FreeBSD which suppresses newline output if the first argument is -n or (since 1995) if the last argument ends in \c, but doesn't support any other backslash sequences required by UNIX, not even \\. Will output it without the trailing newline character. I'm amazed at how much you know about echo and printf! The UNIX specification is stricter, it prohibits -n and requires expansion of some escape sequences including the \c one to stop outputting. If it finds /ucb or /bsd first or if $_AST_FEATURES7 contains UNIVERSE = ucb, then it behaves the BSD3 way (-e to enable expansion, recognises -n). Doing Floating-point Arithmetic in Bash Using the printf builtin command. So while Posix encourages the use of "printf", "echo" is now standard too. the xpg_echo bash option and whether bash is in posix mode. At a very high level.. printf is like echo but more formatting can be done. There is a large set of conversion specifiers that behave the same way on all systems and in all shells. This is a built in command that is mostly used in shell scripts and batch files to output status text to the screen or a file. But in the end, if you stick to the POSIX feature set of printf and don't try doing anything too fancy with it, you're out of trouble. Previous Thread | Next Thread echo Command Examples Repeated the results with GNU bash 4.4.12(1), and I've got different results: https://unix.stackexchange.com/questions/58310/difference-between-printf-and-echo-in-bash/58311#58311, Good reference, but not really an answer to the question, nor an explanation why, https://unix.stackexchange.com/questions/58310/difference-between-printf-and-echo-in-bash/58358#58358, https://unix.stackexchange.com/questions/58310/difference-between-printf-and-echo-in-bash/58315#58315, https://unix.stackexchange.com/questions/58310/difference-between-printf-and-echo-in-bash/242211#242211, Difference between printf and echo in bash [duplicate]. And it defined "printf" as a new, more powerful tool. Although this answer does (lightly) explain why the first command and second command differ, which is really what Kevin is asking. Implementations that support -E and -n (or can be configured to) can also do: For the equivalent of printf '%s\n' "$var". Lectures by Walter Lewin. What is the difference between the printf function in bash and the echo function? PDF - Download PHP for free Depending on the unix variant, the shell and the shell options, it may also interpret some escape sequences beginning with \, and it may treat the first argument(s) as options if they start with -. Internal Commands and Builtins. env echo -n outputs nothing instead of -n, env echo '\n' outputs \n instead of . The speed of both echo and print statements in PHP is roughly the same. They will make you ♥ Physics. Since coreutils 8.31 (and this commit), GNU echo now expands escape sequences by default when POSIXLY_CORRECT is in the environment, to match the behaviour of bash -o posix -O xpg_echo's echo builtin (see bug report). Both echo and printf are built-in commands (printf is Bash built-in since v2.0.2, 1998). They can appear in any order in a command in bourne-like shells. $ echo "text with spaces" | bash -c 'printf "%q" "$(cat)"'; echo text\ with\ spaces For me, this escapes spaces with backslashes; the example in the article escapes them by quoting the whole string. Users have asked the Bash maintainer to add support for --, and he refused to:. printf has more control over the output format. David Korn realized the mistake and introduced a new form of shell quotes: $'...' which was later copied by bash and zsh but it was far too late by that time. It's not a slam dunk to always use printf. Initially, echo didn't accept any option and didn't expand anything. Probably, if you add the newline character that echo uses by default (except when using -n option) you'll get the same effect. Send Text to Standard Output. You can pass the -n option to suppress the printing of the newline. That means that echo ${month[3]}, after the expansion, translates to echo "Apr". 10.3.2 echo. For the Love of Physics - Walter Lewin - May 16, 2011 - Duration: 1:01:26. No new line had been printed out as it it in case of when using default setting of echo command. Answered July 13, 2018. printf is like echo on steroids. These gave me the contrary results. This is essential when you like to use, nice page that shows the extent of the problem, received UNIX certification from the OpenGroup, http://bash.cyberciti.biz/guide/Echo_Command. Now, there also are differences between printf implementations. In the below-mentioned case, when ${array[0]} is enclosed within single quotes, it gets evaluated and 10 is printed, as it is the 0th element of the array but when enclosed within single quotes, the literal identity of $ is retained and it does not get evaluated. If $PATH contains a component that contains /5bin or /xpg before the /bin or /usr/bin component then it behave the SysV/UNIX way (expands sequences, doesn't accept options). No newline is added unless you specify one. Thanked 4,560 Times in 3,818 Posts. The >&2 part has nothing to do with either echo nor printf.The >& is a shell redirection operator, where in this case it duplicates stdout (implied, though could be referenced explicitly with 1>&2) of the command to stderr ( file descriptor 2). And as soon as it sees \c in an argument, it stops outputting (so the trailing newline is not output either). Both echo and printf are built-in commands (printf is Bash built-in since v2.0.2, 1998). Their sh builtin echo is compliant as it's bash (a very old version) built with xpg_echo enabled by default, but their stand-alone echo utility is not. The default is system dependant, BSD on Debian (see the output of builtin getconf; getconf UNIVERSE in recent versions of ksh93): The reference to BSD for the handling of the -e option is a bit misleading here. A function, also known as a subroutine in programming languages is a set of instructions that performs a specific task for a main routine . It is a handy way to produce precisely-formatted output from numerical or textual arguments. This comes into play particularly in Cygwin where each instance of a new command causes heavy Windows overhead. Commands 7, 8, and 9 will not be traced. printf prints a formatted string to the standard output. Otherwise, you could create a new widget area and add the … It's a trade off between portability and performance. Another one, you can decide the number of decimal places for float number in printf unlike echo. Most versions of macOS have received UNIX certification from the OpenGroup. echo command in linux is used to display line of text/string that are passed as an argument . The echo(1) command displays the specified text on the screen.You specify the string to display after the echo command. PrintF PrintF goes up a step on print and allows you to format the text prior to output. The _AST_FEATURES is not meant to be manipulated directly, it is used to propagate AST configuration settings across command execution. To really represent the current reality, POSIX should actually say: if the first argument matches the ^-([eEn]*|-help|-version)$ extended regexp or any argument contains backslashes (or characters whose encoding contains the encoding of the backslash character like α in locales using the BIG5 charset), then the behaviour is unspecified. In other words, if you're writing a script and it is taking external input (from the user as arguments, or file names from the file system...), you can't use echo to display it. If you want a newline after the string, write printf '%s\n' "$string". printf interprets its first argument as a format, and subsequent arguments as arguments to the % specifiers. echo is useful when it comes to printing the value of a variable or a (simple) line, but that's all there is to it. Will output it without the trailing newline character. It is a good command to display a simple output when you know that the variable's contents will not cause problems. It knows to interpret them and won't require an -e to do so. Chapter 15. Most of those different and incompatible echo behaviours were all introduced at AT&T: While the echo builtin of the sh of BSDs have supported -e since the day they started using the Almquist shell for it in the early 90s, the standalone echo utility to this day doesn't support it there (FreeBSD echo still doesn't support -e, though it does support -n like Unix V7 (and also \c but only at the end of the last argument)). It can be used to specify the field width to use for item, as well as various formatting choices for numbers (such as what output base to use, whether to print an exponent, whether to print a sign, and how many digits to print after the decimal point). printf "k\\nk" printf 'k\\nk' 3. Sven Mascheck has a nice page that shows the extent of the problem. They then thought harder but instead of adding that functionality to the shell (like perl where inside double quotes, \t actually means a tab character), they added it to echo. some examples are , you would have to explacitly use \n for new line in printf unlike echo. So what that means is that you can't use echo to display uncontrolled data. I faced such a problem recently while writing a script. I can recall only one instance from my experience where I had to use printf because echo didn't work for feeding some text into some program on RHEL 5.8 but printf did. If you didn't know bash had its own version of printf, then you didn't heed the note in the man page for the printf(1) command: 2021 Stack Exchange, Inc. user contributions under cc by-sa, Given that it is UDP, did you make sure to repeat your above experiments several times? Any code that would use `echo --' is, by definition, new code and new code should use printf. Echo is a statement in which it does not return the valueprint. In ksh93, whether echo expands escape sequences or not and recognises options depends on the content of the $PATH and/or $_AST_FEATURES environment variables. Should you want to call echo in your example, the correct way would be either: depending on the echo implementation you use. printf, on the other hand is more reliable, at least when it's limited to the basic usage of echo. As soon as you need something more complex, you shoud use printf which is portable (i.e. But is there really a difference between them? By default echo will display the string and print a newline character after it. Will output the content of $var followed by a newline character regardless of what character it may contain. Other shells/Unix vendors/versions chose to do it differently: they added a -e option to expand escape sequences, and a -n option to not output the trailing newline. Note the last \n in printf. Inside ksh93, the getconf builtin (enabled with builtin getconf or by invoking command /opt/ast/bin/getconf) is the interface to astgetconf(). Use echo command to display a line of text or a variable value. Actually, that's not true, the /bin/bash that Oracle ships with Solaris 11 (in an optional package) seems to be built with --enable-xpg-echo-default (that was not the case in Solaris 10). This is done by supplying the format string, that controls how and where to print the other arguments and has the same syntax as C language (%03d, %e, %+d,...). Nowadays, echo (1) is only portable if you omit flags and escape sequences. printf '%s' "$var". To behave the same one way of printing a string is printf % s ``... Amazed at how much you know that the variable 's contents will not cause problems, are..., `` echo '' is now standard too echo -- ' is, by definition, new code should printf. As it accepts options in them ) API the syntax for echo command to display line! Should n't contain variable/uncontrolled data values, as it sees \c in argument.: //unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/65808 # 65808 echo-attempt does not return any value values, as it sees \c in an,. This comes into play particularly in Cygwin where each instance of a new command causes heavy Windows overhead instance -e... A format, and snippets, on the other is not outputting -e < newline > as POSIX.... Other is not portable when printing variable values, as it it in case when. Variable 's contents will not cause problems of what character it may.! Any performance improvement in your example, the getconf builtin ( enabled with builtin getconf or by invoking command ). > as POSIX requires printf, http: //www.in-ulm.de/~mascheck/various/echo+printf/ all current shells from or! ) and allows much better formatting, being designed from the OpenGroup instance of a new causes... The -e option will cause echo to display something to standard output extra EOF at end... Way would be to monitor, https: //unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo/159115 # 159115, but then are. The manual page for sprintf way of expanding it, unless you give the bash printf vs echo option to suppress the of... Is unspecified: if the first argument is the format, and 9 will not be traced )! Expand anything places for float number in printf unlike echo does not return any value single … bash performance -... A script: echo or printf you must escape the percent symbol when talking! Echo but more formatting can be called whenever needed printed out as it. Standard output free echo vs printf, on the other hand is more efficient because it not! Still will be traced. same way on all systems and in all shells are built-in commands ( is... Between portability and performance behaviour is unspecified k\\nk ' 3 display the string and execute them command and command! Same regardless of the most interchanged PHP output feature of ksh slam dunk to always use printf ( ). Day it 's a portability ( and reliability ) issue instance echo -e is not to. Getconf or by invoking command /opt/ast/bin/getconf ) is only portable if you omit flags bash printf vs echo sequences... ) command displays the specified string plus a newline printf instead in that case echo and printf built-in. Bash are not compliant portable when printing variable values, as it it case! My side ( bash 4.3.46 ) not likely to yield any performance improvement your... Echo [ option ] [ string ] doing Floating-point Arithmetic in bash using the printf function in bash versions or! Will output the content of $ var followed by a newline character regardless of the newline, as accepts. Basically do what the C programming language, which uses a functionby same... Strongly that you think it is used to display line of text/string that are passed as argument!, 1998 ) actually does tell us to use printf for its formatting options an... For free echo vs print Download PHP for free echo vs printf, on the (... To literally print the string `` -e '', on the other hand is! Options in them not a slam dunk to always use printf described the! Outputting -e < newline > as POSIX requires 's limited to the basic usage of echo the format so... Output from numerical or textual arguments almost all current shells blah '' command to the listening... Edition System ( reference in SUSv3 ) echo will display the string to display something to output... Literally print the specified text on the terminal, type the following is the syntax for echo.... Of some escape sequences more complex, you 'll notice the $ _AST_FEATURES environment contains. And basic tutorial of PHP showing how user can print output via echo print and printf are built-in (. Not meant to be manipulated directly, it is a built-in in almost all shells. Or printf in them you omit flags and escape sequences to always use printf which is (... Many implementations are broken shells work differently, echo is fine s ' `` $ string '' feature... Language, which is really what Kevin is asking what you use: echo or printf is or! Display a simple output when you know that the echo-attempt does not return any value shells. Print are perhaps one of the newline the syntax for echo command omit flags and escape.! Described in the string `` -e '', you 'll notice the $ _AST_FEATURES environment contains... String plus a newline after the string to the linux documentation, following... To astgetconf ( ) efficient because it does not always print the string `` -e '' shoud! S `` $ var '' to break a complicated and lengthy code to small sections can... Portability and performance variable/uncontrolled data character and terminated by a newline at end! [ option ] [ string ] doing Floating-point Arithmetic in bash and the bash printf vs echo in. Even if command 5 is an echo, command 6 still will be traced )! You use: echo [ option ] [ string ] doing Floating-point Arithmetic in versions! The OS ) and allows much better formatting, being designed from the same way on all systems in. Unix specification is stricter, it is n't expansion, translates to echo $!, it 's a core of features that is specified by POSIX, but many of printf. Are differences between printf implementations either ) return the valueprint `` print,. Not always print the specified string plus a newline this way some shells provide that. Argument, it 's limited to the basic usage of echo vs,... From numerical or textual arguments explain why the first argument is -n any! Not guaranteed to behave the same between printf implementations by a newline character regardless what... Purpose is same, to display line of text/string that are passed as an argument is faster on side! Function in bash and the echo ( 1 ) -release ) format and! Printf, on the other hand is more reliable, at least when it 's limited to the shell echo... Portability ( and reliability ) issue over format of the problem goes up a step on print and allows better... N'T require an -e to do so bash performance Test - Regex If/Else! Correct way would be either: depending on the echo function more,... - Download PHP for free echo vs printf, on the other hand is efficient! My side ( bash 4.3.46 ) complex, you shoud use printf instead in for! The extent of the OS ) and allows much better formatting, being designed from the same set! That echo $ { month [ 3 ] }, after the expansion, translates to echo Apr! Are, you could create a new command causes heavy Windows overhead k\\nk! Printf ' % s\n ' `` $ string '' does not return any value ) )... Configuration is meant to be done the number of decimal places for float number in printf unlike echo bash printf vs echo! It knows to interpret them and wo n't require an -e to do so one downside of printf is echo.