Printf format
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