Home > Operation and Maintenance > Linux Operation and Maintenance > Detailed explanation of the usage of printf in Linux shell

Detailed explanation of the usage of printf in Linux shell

巴扎黑
Release: 2017-09-11 11:16:08
Original
1895 people have browsed it

This article mainly introduces the relevant information about the detailed usage of printf in Linux shell. I hope this article can help everyone. Friends in need can refer to

printf in Linux shell. Detailed usage

One syntax

printf 'Output type output format' Output content

Output type:

%ns: Output string. n is a number referring to how many characters are output.
%ni: Output integer. n is a number referring to how many numbers are output.
%m.n: Output floating point number. m and n are numbers, which refer to the number of integer digits and decimals output. For example, %8.2 represents a total of 8 digits output, of which 2 digits are decimals and 6 digits are integers.

Output format:

Second actual combat


[root@localhost ~]# printf %s 1 2 3 4 5 6
123456[root@localhost ~]# printf %s %s %s 1 2 3 4 5 6
%s%s123456[root@localhost ~]# printf '%s %s %s' 1 2 3 4 5 6
1 2 34 5 6[root@localhost ~]# printf '%s\t%s\t%s\n' 1 2 3 4 5 6
1 2 3
4 5 6
[root@localhost ~]# printf '%s' $(cat student.txt)
1furongF852fengjF603cangF70[root@localhost ~]#
[root@localhost ~]# printf '%s\t%s\t%s\t%s\n' $(cat student.txt)
1 furong F 85
2 fengj F 60
3 cang F 70
Copy after login

The above is the detailed content of Detailed explanation of the usage of printf in Linux shell. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template