Receive all updates via Facebook. Just Click the Like Button Below

User Intraction in Shell Scripts

In some cases the script needs to intract with the user and accept inputs.
In shell scripts we use the read statement to take input from the user.

1

The read statement in Linux Shell Scripting

2

The Read Statement
Used to get input (data from user) from keyboard and store (data) to variable.

Syntax:
read variable1, variable2,...variableN

Lets write a shell script to ask the user his name and print it. While running this script it waits for the user input.

 
#Script to read your name from key-board
echo "Enter your name:"
read name
echo "Hello $name, Welcome to the world of Linux!"
            

Result
Save the above file as your-name.sh
Run it as follows:
$ chmod 755 your-name.sh
$ ./your-name.sh
Enter your name: Tom
Hello Tom, Welcome to the world of Linux!

3

Related posts:

Advertise here

picture picture

Follow us

picture

- Tech-Tutorials twitter.com/techcuriosity

Like us

About Techcuriosity

I am Telson, the webmaster of Techcuriosity.com and through this site, I share my knowledge and curiosities in the Tech World.


What We Offer

  • What is ..?
  • How to ..?
  • Difference between ..?
  • How .. works?
  • Get in Touch

    techcuriosity@gmail.com
    UK : +44 77 33 890 678

    picture picture

    Our Partners

  • Website Design Dubai
  • SEO Link Exchange
  • picture

    picture