shell之echo and printf
#!/bin/sh
_________echo___________
#read name
#echo "$name It is a test" #read命令從標(biāo)準(zhǔn)的輸入中讀取一行,并把輸入方的每個(gè)字段的值指定給shell變量
#echo "OK! \n"
#echo -e "OK! \n" # -e 開(kāi)啟轉(zhuǎn)義
#echo -e "ok! "
#echo "It is a test !!!" > myfile
#echo `date`
#read firststr secondstr
#echo "第一個(gè)參數(shù):$firststr;第二個(gè)參數(shù):$secondstr"
read -p "請(qǐng)輸入一段文字:" -n 6 -s password
echo -e "\npassword is $password"
#-p 輸入提示文字
#-n 輸入字符長(zhǎng)度限制(達(dá)到6位,自動(dòng)結(jié)束)
# -t 輸入限時(shí)
#-s 輸入隱藏內(nèi)容
__________printf__________
#!/bin/sh
#printf 也是一個(gè)shell輸出命令命令模仿c程序庫(kù)(library)里的printf()程序,移植性比echo好,語(yǔ)法:printf format-string [arguments...],參數(shù)一:格式控制的字符串,參數(shù)二:參數(shù)列表
#printf 'hello,shell\n'
#printf "%-10s %-8s %-4s\n" 姓名 性別 體重KG
#printf "%-10s %-8s %-4s\n" 郭靖 男 66.1234
#printf "%-10s %-8s %-4s\n" 楊過(guò) 男 48.6543
#printf "%-10s %-8s %-4s\n" 郭芙 女 47.9876
#%s %c %d %f 都是格式替代符
#%d Decimal 十進(jìn)制整數(shù) -- 對(duì)應(yīng)位置參數(shù)必須是十進(jìn)制整數(shù),否則報(bào)錯(cuò)
#%s String 字符串 -- 對(duì)應(yīng)位置參數(shù)必須是字符串或者字符型,否則報(bào)錯(cuò)!
#%c: Char 字符 -- 對(duì)應(yīng)位置參數(shù)必須是字符串或者字符型,否則報(bào)錯(cuò)!
#%f: Float 浮點(diǎn) -- 對(duì)應(yīng)位置參數(shù)必須是數(shù)字型,否則報(bào)錯(cuò)
#printf "%d %s\n" 1 "abc"
#printf '%d %s\n' 1 "abc" #單引號(hào)與雙引號(hào)的輸出效果一致
#printf %s hello,world! #沒(méi)有引號(hào)也可以輸出
#printf %s hello world #只制定了一個(gè)參數(shù),但多出的參數(shù)仍然會(huì)按照該格式輸出,format-string被重用
# printf "%s\n" hello world
# printf "%s %s %s \n" a b c d e f g h i j
# printf '%s and %d \n' #如果沒(méi)有arguments,那么%s用null代替,%d用0代替
# #轉(zhuǎn)義序列:
# \a 警告字符
# \b 后退
# \c 抑制(不顯示)輸出結(jié)果中任何結(jié)尾的換行字符(只在%b格式指示符控制下的參數(shù)字符串中有效)
# \f 換頁(yè)(formfeed)
# \n 換行
# \r 回車(chē)(Carriage return)
# \t 水平制表符
# \v 垂直制表符
# \\ 一個(gè)字面上的反斜杠字符
# \ddd 表示1到3位數(shù)八進(jìn)制值的字符。僅在格式字符串中有效
# \0ddd 表示1到3位的八進(jìn)制值字符
printf '%s and %d and %c and %4.4f \n ' '1+1=' 2 'True' 12323.1415
?
資源來(lái)自:http://www.runoob.com/
轉(zhuǎn)載于:https://www.cnblogs.com/qtclm/p/10314511.html
總結(jié)
以上是生活随笔為你收集整理的shell之echo and printf的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: vue click事件冒泡,默认行为
- 下一篇: 在 Mac 上多开微信,还能看到朋友撤回