首頁  >  文章  >  運維  >  詳細講解Linux shell中的printf的用法

詳細講解Linux shell中的printf的用法

巴扎黑
巴扎黑原創
2017-09-11 11:16:081829瀏覽

這篇文章主要介紹了Linux shell中的printf的詳細用法的相關資料,希望能透過本文能幫助到大家,需要的朋友可以參考下

Linux shell中的printf的詳細用法

一語法

printf '輸出類型輸出格式' 輸出內容

輸出類型:

%ns:輸出字串。 n是數字指稱輸出幾個字元。
%ni:輸出整數。 n是數字指涉輸出幾個數字。
%m.n:輸出浮點數。 m和n是數字,指輸出的整數位數和小數

如%8.2代表共輸出8位數,其中2位是小數,6位是整數。

輸出格式:

 二實戰


### 二實戰##################
[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

以上是詳細講解Linux shell中的printf的用法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn