当前位置:网站首页>(5) Printf (instead of echo)
(5) Printf (instead of echo)
2022-07-27 11:22:00 【Hungry Taibai Xingjun】
#!/bin/bash
# printf from POSIX Standard definition , Therefore use printf The script is better than using echo Good portability
# (1) Use reference text and spaces to separate parameters
# (2) Can be found in printf Using format string , You can set the string width 、 The odd way of left and right
# (3) Default printf I don't want to echo Automatically add line breaks , have access to \n
# (4) grammar : printf format-string [arguments...]
# format-string: Format control string
# arguments: parameter list
printf "%-10s %-8s %-4s\n" full name Gender weight kg
printf "%-10s %-8s %-4.2f\n" Zhang San aaaaaaaaaaaaaaaaaaaaaa Woman 55.5555
printf "%-10s %-8s %-4.2f\n" Li Si male 66.5775
printf "%-10s %-8s %-4.2f\n" Wang Wu Woman 55.1234
# %s: Output a string
# %c: Output a character
# %d: Output an integer
# %f: Output a decimal
# %-10s: A width of 10 Character string (- Indicates left alignment , There is no right alignment ), Not enough space to fill , Show all of more
# %-4.2f: It means to format it as a decimal , among .2 Finger retention 2 Decimal place .
printf '%d %s\n' 1 "2"
printf '%d %s\n' "1" '2'
# printf %d %s 1 2 #error
# Escape character
:<<EOF
\a Warning characters , Usually it is ASCII Of BEL character
\b back off
\c Inhibition ( No display ) Any ending newline characters in the output result ( Only in %b Valid in parameter string under format indicator control ), and , Any character left in the parameter 、 Any subsequent parameters and any characters left in the format string , All ignored
\f Change the page (formfeed)
\n Line break
\r enter (Carriage return)
\t Horizontal tabs
\v Vertical tabs
\\ A literal backslash character
\ddd Express 1 To 3 The character of a digit octal value . Valid only in format string
\0ddd Express 1 To 3 The octal character of a bit
EOF
边栏推荐
- Win10 vscode code code format setting and remote breakpoint debugging
- 背包模型 AcWing 423. 采药
- 2022牛客多校 (3)J.Journey
- tensorflow运行报错解决方法
- Wilderness search --- search iterations
- Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
- Knapsack model acwing 423. Picking herbs
- 数字三角形模型 AcWing 275. 传纸条
- Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
- Pat (Grade B) 2022 summer exam
猜你喜欢

最长上升子序列模型 AcWing 1010. 拦截导弹

Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing

Digital triangle model acwing 1018. Minimum toll

Find the combinatorial number acwing 889. 01 sequence satisfying the condition

最长上升子序列模型 AcWing 1016. 最大上升子序列和

最长上升子序列模型 AcWing 1014. 登山

PAT(乙级)2022年夏季考试

Quantitative industry knowledge summary

最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼

博弈论 AcWing 893. 集合-Nim游戏
随机推荐
Memory search acwing 901. Skiing
2022牛客多校 (3)J.Journey
Sorry, you guys have something to deal with in the bank recently, which has been delayed
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
FAQs of "relay chain" and "dot" in Poka ecosystem
求组合数 AcWing 888. 求组合数 IV
Remember an experience of using canvas to make the banner streamer effect of Tencent cloud homepage
The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
洛谷P1441 砝码称重
I've compromised. Since everyone wants to call me Yelin, there's nothing I can do
Solutions to errors in tensorflow operation
IO stream_ Character stream, IO stream summary, IO stream case summary
A deep analysis of the soul of C language -- pointer
树形DP AcWing 285. 没有上司的舞会
栈 AcWing 3302. 表达式求值
Remember not to copy your group work, students. Fortunately, you only passed two questions. Don't have an accident
状态压缩DP AcWing 91. 最短Hamilton路径
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
中国剩余定理 AcWing 204. 表达整数的奇怪方式
Lazy loading of lists and pictures