Bash Script wait for user Input Command

If you are writing a bash script and you are fetching input from the user and you want to wait for the user input, then you can make use of the read command with a -p (prompt) option.

Let's take a look at an example script.



read -p "Enter Your Name: " user_name 
echo "Hello: $user_name"
Enter Your Name: Sam
Hello: Sam

You will see that the script waits for user to enter their name and only returns when enter key is pressed.

Bash Script wait for user Input Command Example

Facing issues? Have Questions? Post them here! I am happy to answer!

Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap