Linux中接收鍵盤輸入


read 選項 變量名
  -p    "提示信息"
  -t     指定等待時間,不指定則一直等待
  -n    指定接收的字符數,不指定則不限制
  -s    隱藏輸入的數據,適用於機密信息的輸入

[root@localhost sh]# vi param_test3.sh
[root@localhost sh]# cat param_test3.sh
#!/bin/bash

# 提示用戶輸入並等待30秒,並將輸入結果存入name變量中
read -t 30 -p "Please input you name: " name
echo -e "\n"
echo "Name is $name"

# 加上 -s 以后 輸入age的時候將隱藏起來
read -s -t 30 -p "Please input you age: " age
echo -e "\n"
echo "Age is $age"

# -n 1 代表只接收一個字符
read -n 1 -t 30 -p "Please input gender M/F :" gender
echo -e "\n"
echo "Genger is $gender"

[root@localhost sh]# sh param_test3.sh
Please input you name: xiaol
Name is xiaol
Please input you age:
Age is 12
Please input gender M/F :M
Genger is M
[root@localhost sh]#


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM