ex47.sh
来自「Shall高级编程」· Shell 代码 · 共 41 行
SH
41 行
#!/bin/bash# printf demoPI=3.14159265358979DecimalConstant=31373Message1="Greetings,"Message2="Earthling."echoprintf "Pi to 2 decimal places = %1.2f" $PIechoprintf "Pi to 9 decimal places = %1.9f" $PI # It even rounds off correctly.printf "\n" # Prints a line feed, # Equivalent to 'echo' . . .printf "Constant = \t%d\n" $DecimalConstant # Inserts tab (\t).printf "%s %s \n" $Message1 $Message2echo# ==========================================## Simulation of C function, sprintf().# Loading a variable with a formatted string.echo Pi12=$(printf "%1.12f" $PI)echo "Pi to 12 decimal places = $Pi12" # Roundoff error!Msg=`printf "%s %s \n" $Message1 $Message2`echo $Msg; echo $Msg# As it happens, the 'sprintf' function can now be accessed#+ as a loadable module to Bash,#+ but this is not portable.exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?