In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "what does printf in linux refer to?", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what printf refers to in linux" article.
In linux, printf means formatted output. This command can better control the output format, the main function is to output text according to the specified format, the command will not wrap the output text, the syntax is "printf format parameters".
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What does printf mean in linux
When writing shell scripts, we use echo to print to standard output. Echo is a simple command, but its functionality is limited. For better control over the output format, you can use the printf command.
The syntax format of printf:
# printf format parameters
Here is an example:
[root@localhost ~] # printf "name:% s\ nheight:% dcm\ nweight:% dkg\ n" Xiaoming "180," 75" name: Xiaoming height: 180cm weight: 75kg
"name:% s\ nheight:% dcm\ nweight:% dkg\ n" is the format, "Xiaoming"180"75" is the parameter. The format contains% s,% d is a format conversion character, and the parameter corresponding to% d must be a decimal number. The parameter for s must be a string. Three newline characters are also included. The printf command does not add line return symbols by default, but needs to be added manually.
Commonly used escape characters
\ "- escaped double quotation marks
\-backslash after escape
\ b-backspace character
\ n-newline character
\ r-carriage return
\ t-horizontal tab character
\ v-Vertical Tab
%%-single% symbol
Commonly used type conversion characters
The type conversion specifier is a character that specifies how to interpret the corresponding parameter, which must be added. The following is a list of all types of conversions and their functions:
% d-print parameters as decimal integers
% f-print parameters as floating-point numbers
% s-print parameters as strings
% x-prints parameters as hexadecimal integers
% o-print parameters as octal integers
Example one
This example uses% dforce% xmy% o to convert the parameters provided later into decimal, hexadecimal, and octal.
[root@localhost ~] # printf "Decimal:% d\ nHex:% x\ nOctal:% o\ n" 100 100 100Decimal: 100Hex: 64Octal: 144
Example two
The following example uses% .2f, where .2 means that the parameter retains two decimal places and f prints the parameter as a floating point number.
[root@localhost] # printf "% .2f\ n" above 3.14159263.14 is about "what is printf in linux"? I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.