KandZ – Tuts

We like to help…!

Linux CLI 56 🐧 shell scripts input text

a - read command in shell scripts
read command is used to accept input from the user
It reads one line from standard input (usually keyboard)
Then it assigns it to one or more variables
common options: -p → displays a custom prompt
-n n → read exactly n characters
-d "d" → provides a different delimiter
-s → silent input (for passwords)
-t n → waits for input up to n seconds

b - read command examples
read name → basic input
read fname lname → multiple variables input
read -p "Please enter your age: " age → custom prompt
read -s -p "Enter your password: " password → silent input
read -n 1 -p "Press any key to continue..." response → specific number of character
read -t 5 -p "Enter your name within 5 seconds: " name → input time out

Leave a Reply