readread 用來讓 script 暫停,等待使用者輸入,然後把輸入值存進變數。
echo "Enter your skill:"
read SKILL
echo "Your skill is $SKILL"
執行到 read 時,bash 會停下來等使用者輸入,按下 Enter 後繼續。
p 選項:提示輸入可以在同一行加上提示字:
read -p "Enter your skill: " SKILL
echo "Your skill is $SKILL"
這樣不需要額外的 echo。
s 選項:隱藏輸入常用於輸入密碼等機密資訊。
#!/bin/bash
echo "Enter your skills:"
read SKILL
echo "Your $SKILL skill is in high Demand in the IT Industry."
read -p 'Username: ' USR
read -sp 'Password: ' pass
echo
echo "Login Successfull: Welcome USER $USR,"

s 會讓輸入的內容不顯示在螢幕上。echo 是為了在輸完密碼後換行。
在自動化或 DevOps 環境中,不建議讓 script 互動式要求輸入,因為: