Wednesday 11 December 2013

Shell Scripting - Read User Input

Inorder to accept user defined input in a shell script, make use of the read command. Try a simple example in Terminal.

Eg:

#!/usr/bin/bash
echo "Please enter your name"
read name
echo "Welcome to shell scripting $name"

Make sure the bash interpreter location is correctly defined in the shebang statement. Else you would see the error like - bad interpreter: No such file or directory

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker