I need help with 'combining 2 while loops' together.
The 1st while loop reads an input and checks to see if the input is a blank.
But at the same time, I want to check if the input (if its not blank) is a number or a word. As I am using the case, I cannot use any if loops.
Really appreciate anyone who can help me. Thank you very much.
#!/bin/bash
read Name in
while [ -z "${Name}" ] #Ensure that there are no blank inputs
do
echo "You cannot input a blank name. Enter a valid name"
read Name
done
read Check in
while [ `echo $Check | grep "[^A-Z]"` ] #Check that user types in character from A-Z only
do
echo "Invalid input. Please enter characters from A-Z";
read Check;
done
Sorry, I'm new to this forum. Will use the code tag in future.
The input should be a word, not a number. If the input is a number, it will keep looping and echoing an invalid statement until the input is a word.
The problem I am facing is, the first loop is working, I cannot input a blank, but I can still input numbers.
I am thinking of something like this
read Name
while [ -z "${Name}" |`echo $Name | grep "[^A-Z]"`]
do
echo "You cannot input a blank or numeric name."
read Name
done
Yes, and I realised that the 'in' does not affect anything. Will remove it.