Thursday, December 8, 2016

handling blank iputs in a shell script.


Here is simple script to handle blank inputs in your interactive shell scripts.

#!bin/sh
while :
echo "enter value for a:";read -r a;  do
         if [ -z "${a}" ]; then
         echo "That was empty, do it again!"

        else ## echo "Checking now..."
                echo "value passed is :$a"
                echo "valid input received."
                break
    fi
done

echo "We are out of loop:"

Sample Output :

[Linux01] $ . Test_input11.sh
enter value for a:

That was empty, do it again!
enter value for a:

That was empty, do it again!
enter value for a:

That was empty, do it again!
enter value for a:
1
value passed is :1
valid input received.
We are out of loop:

No comments:

Post a Comment