How to read user input in bash script

Many times we need to provide user input to the bash script to take actions accordingly. We can use bash builtin “read” command for same. Let’s see a quick example

#!/bin/bash
echo "Provide some input :"
read XYZ
echo "You have typed $XYZ"

 

As we see we are reading input to a runtime variable named as “XYZ”. We can use value of the variable anywhere in the script once we have the value.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.