Linux shell中的printf的詳細(xì)用法
一 語(yǔ)法
printf '輸出類(lèi)型輸出格式' 輸出內(nèi)容
輸出類(lèi)型:
%ns:輸出字符串。n是數(shù)字指代輸出幾個(gè)字符。
%ni:輸出整數(shù)。n是數(shù)字指代輸出幾個(gè)數(shù)字。
%m.n:輸出浮點(diǎn)數(shù)。m和n是數(shù)字,指代輸出的整數(shù)位數(shù)和小數(shù)
如%8.2代表共輸出8位數(shù),其中2位是小數(shù),6位是整數(shù)。
輸出格式:

二 實(shí)戰(zhàn)
[root@localhost ~]# printf %s 1 2 3 4 5 6123456[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 61 2 34 5 6[root@localhost ~]# printf '%s/t%s/t%s/n' 1 2 3 4 5 61 2 34 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 852 fengj F 603 cang F 70
如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
|
新聞熱點(diǎn)
疑難解答
網(wǎng)友關(guān)注