From the course: Linux System Engineer: Bash Shell Scripting for Automation

Unlock the full course today

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

Prompt for input

Prompt for input

From the course: Linux System Engineer: Bash Shell Scripting for Automation

Start my 1-month free trial

Prompt for input

- [Instructor] Another method of getting data into a script is to prompt the user. This is solely for interactive programs. To prompt the user, we'll be using the read command again. Make sure you're in your tilde slash bin directory and lets create a new script. Type in, vi space promptuser.sh and hit enter. Go onto insert mode and add to this file hash bang slash bin slash bash new line read space dash P space double quote enter your name colon space double quote username. New line echo space double quote your name is colon space dollar sign username double quote. Here we're using read to prompt the user, whatever they type in will be assigned to the variable named username which we chose. Save by pressing escape colon W and hitting enter. Now go to a second terminal tab, make your script executable and run it type in chmod space U plus X space promptuser.sh and then type in promptuser.sh and hit enter, enter your name and hit enter again. Other options for read that can be handy…

Contents