How to accept user input in shell script?

To accept input in shell script, read command is used.

The following program shows the working of read command


#!/bin/sh

echo What is your name?

read name

echo Good Morning $name

Let’s check the output


What is your name?

User

Good Morning User

As you can see that using the read command, the shell script is blocked until the user input is entered and the return key pressed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s