From the course: Learning Linux Shell Scripting

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Getting input from users

Getting input from users - Linux Tutorial

From the course: Learning Linux Shell Scripting

Start my 1-month free trial

Getting input from users

- [Instructor] In order to make our script interactive, we need to be able to get input from the user. From the terminal we're gonna do a touch, prompt.sh, change mode 755 prompt.sh, and atom prompt.sh. Put in our shebang. Bin forward slash env space bash, and then we're gonna begin with the read command. And we're gonna say read dash p, and this next part is the prompt message the user will see. What is your first name colon space, and then all caps name. The dash p prompts the output string without adding a new line character. This keeps the user's input on the same line as the prompt. Name is gonna be the variable that the string that the user types' gonna go into so then we're gonna say echo your name is, and let put colon right there, dollar sign name, and just an exit zero. Save that off, go to the Terminal. Dot forward slash prompt.sh, and it'll ask us what is our name? I'll say Troy, and it'll respond your name is Troy. We used the read command to get input from the user.

Contents