shell命令获取按键值_linux shell获取键盘输入
linux shell從鍵盤獲取輸入
代碼1:
#!/bin/bash
#提示“Input your choice:”,把用戶的輸入保存入變量choice_user中
read -p "Input your choice:" choice_user
echo "your choice:${choice_user}"
#提示“請輸入姓名”并等待30秒,把用戶的輸入保存入變量name中
read -t 30 -p "請輸入用戶名稱:" name
echo -e "\n"
echo "用戶名為:$name"
#提示“請輸入密碼”并等待30秒,把用戶的輸入保存入變量age中,輸入內(nèi)容隱藏
read -t 30 -s -p "請輸入用戶密碼:" age
echo -e "\n"
echo "用戶密碼為:$age"
#提示“請輸入性別”并等待30秒,把用戶的輸入保存入變量sex中,只接受一個(gè)字符輸入
read -t 30 -n 1 -p "請輸入用戶性別:" sex
echo -e "\n"
echo "性別為$sex"
read命令說明:
read [選項(xiàng)][變量名]
選項(xiàng):
Read的一些選項(xiàng)
Read可以帶有-a, -d, -e, -n, -p, -r, -t, 和 -s八個(gè)選項(xiàng)。
-a :將內(nèi)容讀入到數(shù)值中
echo -n "Input muliple values into an array:"</
總結(jié)
以上是生活随笔為你收集整理的shell命令获取按键值_linux shell获取键盘输入的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python人头识别_python+op
- 下一篇: linux 其他常用命令