read:是shell基本讀取函式
基本用法:
read [選擇引數] [接受變數] (預設讀取鍵盤輸入)
-p指定要顯示的提示
-s靜默輸入,一般用於密碼
-n #
指定輸入的字元長度最大值#
-d 『字元』
輸入結束符,當你輸入的內容出現這個字元時,立即結束輸入
-t n
超出n秒沒有進行輸入,則自動退出。
例項:
read //未指定變數,讀取資料存放在環境變數reply中
read name //讀取鍵盤輸入,存放於name變數中,後面引用$name使用
read -p 「請輸入名字」 name //增加-p引數,指定提示內容
read name age // 指定讀取多個變數,鍵盤輸入時以空格分開兩個值
read -t 5 name // -t 增加讀取超時時限
read -s name //靜默輸入,輸入密碼
#使用 stty ‐echo 關閉 shell 的回顯功能
#使用 stty echo 開啟 shell 的回顯功能
stty -echo
read -p "請輸入密碼: " pass
stty echo
shell指令碼read傳遞引數
1.用read獲取使用者的輸入 舉例 example.sh,檢視 cat example.sh bin bash this is a sample script file.accept user input for demonstration.使用read命令將使用者的輸入儲存到變數name中 ec...
shell指令碼之輸入互動read
這個 read 內部命令被用來從標準輸入讀取單行資料。這個命令可以用來讀取鍵盤輸入,當使用 重定向的時候,讀取檔案中的一行資料。這個命令有以下語法形式 read options variable.這裡的 options 是下面列出的可用選項中的乙個或多個,且 variable 是用來儲存輸入數值的乙...
Shell中read的用法詳解
read的常用用法如下 read ps var1 var2 p 提示語句 n字元個數 s遮蔽回顯 t等待時間 d輸入分界 01 read 從標準輸入讀取一行並賦值給特定變數reply root linux read hello,world root linux echo reply hello,wo...