0

So I recently noticed there are two "versions" of printf in my Ubuntu server 18.04.

Please see this output :

[~]@ubuntu-s-1vcpu-1gb-nyc3-01  
(0) matias #> which printf
/usr/bin/printf
[~]@ubuntu-s-1vcpu-1gb-nyc3-01  
(0) matias #> type printf
printf is a shell builtin
[~]@ubuntu-s-1vcpu-1gb-nyc3-01  
(0) matias #> /usr/bin/printf --version
printf (GNU coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.
[~]@ubuntu-s-1vcpu-1gb-nyc3-01  
(0) matias #> printf --version
-bash: printf: --: invalid option
printf: usage: printf [-v var] format [arguments]
[~]@ubuntu-s-1vcpu-1gb-nyc3-01  
(0) matias #> printf '\U1F339'
[~]@ubuntu-s-1vcpu-1gb-nyc3-01  
(0) matias #> /usr/bin/printf '\U1F339'
/usr/bin/printf: missing hexadecimal number in escape
[~]@ubuntu-s-1vcpu-1gb-nyc3-01  
(0) matias #> 

They also work differently as you can see in the output when trying to print a rose with Unicode.

My main questions are, why is there a builtin printf and a binary and not only one of them? How can I know which one to use?

I can see the printf binary is NEWER than my Bash version.

(0) matias #> bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Matias Barrios
  • 276
  • 2
  • 12

0 Answers0