Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Printf format

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Format:

printf format [string]

printf format parameter

Because printf behavior is defined by the POSIX standard, scripts using printf are more portable than those using echo.

Procedure:

#!/ bin/bash

printf "%-10s %-8s %-4s\n" Name Sex Weight kg

printf "%-10s %-8s %-4.2f\n" Guo Jingnan 66.1234

printf "%-10s %-8s %-4.2f\n" Yang Guonan 48.6543

printf "%-10s %-8s %-4.2f\n" Guo Fu Female 47.9876

# format-string is double quotes

printf "%d %s\n" 1 "abc"

#Single quotes work just like double quotes

printf '%d %s\n' 1 "abc"

Run Results:

Name Sex Weight kg

Guo Jingnan 66.12

Yang Guo Male 48.65

Guo Fu Female 47.99

1 abc

1 abc

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report