Showing posts with label Make your Shell Script interactive using read command. Show all posts
Showing posts with label Make your Shell Script interactive using read command. Show all posts

Tuesday, May 22, 2018

Make your Shell Script interactive using read command,Linux Teacher Sourav,Kolkata 09748184075

#!/bin/sh
#
# 23/05/2018
#
echo "Usage Of Read Command in Linux"
rc=0 # return code
while [ $rc -eq 0 ]
do
read -p "Enter value or q to quit: " var
echo "var: $var"
if [ "$var" = "q" ] ; then
rc=1
fi
done
rc=0 # return code
while [ $rc -eq 0 ]
do
read -p "Password: " -s var
echo ""
# carriage return
echo "var: $var"
if [ "$var" = "q" ] ; then
rc=1
fi
done
echo "Press some keys and q to quit."
rc=0
# return code
while [ $rc -eq 0 ]
do
read -n 1 -s var # wait for 1 char, does not output it
echo $var # output it here
if [ "$var" = "q" ] ; then
rc=1
fi
done
exit $rc