

With ANSI-C quoting using $'.', escape sequences are replaced in output according to the standard. In an effort to improve portability amongst compilers, the ANSI C Standard was established in 1983. It’s important for programmers to ensure they carefully handle user input. Though printf has further options that make it a far more powerful replacement of echo, this utility is not foolproof and can be vulnerable to an uncontrolled format string attack. The character sequence \n ensures the output ends with a newline: printf "%b\n" "Many females in Oble are \noblewomen" To interpret backslash escape sequences, use %b. It allows you to use format specifiers to humanize input.
How to get putty to show newline characters portable#
Since 4th Edition Unix, the portable printf command has essentially been the new and better echo. The POSIX specification recommends the use of printf in new programs. In modern systems, it is retained only to provide compatibility with the many programs that still use it. Additionally, its usage in conjunction with user input is relatively easy to corrupt through shell injection attack using command substitutions. # the study of European nerves is \neurologyĮcho -e "the study of European nerves is \neurology"īecause of these inconsistencies in implementations, echo is considered non-portable. Where echo on some systems will automatically expand escape sequences, others require a -e option to do the same: echo "the study of European nerves is \neurology" Using echoįrom its appearance in Multics to its modern-day Unix-like system ubiquity, echo remains a familiar tool for getting your terminal to say “Hello world!” Unfortunately, inconsistent implementations across operating systems make its usage tricky. The expansion of the placeholder \n can be accomplished in a multitude of ways, each with its own unique history and complications. The job of printing output to a terminal is fraught with quirks for programmers to navigate, as exemplified by the deceptively nontrivial task of expanding an escape sequence to print newlines. These advancements have not been seamless. Technology throughout the computing age has tried to solve this problem, from the use of ASCII characters in video computer displays to modern shell commands like echo and printf. But humanizing and displaying stdout is another matter.
:max_bytes(150000):strip_icc()/7lpoMXSuqb-b9bfc0dbe5f34610be65f1d65305f041.png)

With the introduction of standard streams and specifically standard output, programs gained a way to talk to each other using plain text streams. Surprisingly, getting computers to give humans readable output is no easy feat.
