Validating user input is not blank

Trying to create a script in BASH that would ask the user to enter another user name making sure the input is not blank before they hit enter then to check the home directory of that user does exist, I have the check folder sorted it's just the loop to make sure the user has entered chars

As a start:

while read a; do
     if [[ -z "${a}" ]]; then
          echo "That was empty, do it again!"
     else
          echo "Checking now..."
          break
     fi
done
echo out of the loop we go
exit 0

To test if a directory exists, use the -d switch of test or shell.

Yeah I have the directory thing sorted but having trouble with the above :frowning:

#!/bin/bash
 
cd /home/
 
echo -n "Enter Users Name : "
read name
while read a; do
     if [[ -z "${a}" ]]; then
          echo "That was empty, do it again!"
     else
          echo "Checking now..."
          break
     fi
done
# End of the loop
exit 0
 
if [ -d $name ]; then
echo That User Exists
else
echo No Such User!!
fi

You are asking 2 times for a name:

That's one too much and you should decide if you use the variable name or a.

And when you test for a user, if it exists, use the tool "id <username>" maybe and check it's exit code with testing $?.
Testing with -d really just tests if the directory exists, but not if the user exists, which is a difference.

Oh god I'm such a novice at all this linux.... Can understand what you mean about the username as yeah I was just checking in the home directory for the user name ... this could be renamed ...

as for the script ggrrrrrr

I been looking for a solution all day 10pm here and i'm so damned tired but I don't want to goto bed till I get this part of the script running. :frowning:

Linux and Unix are time consuming stuff. Best sleep over it and start fresh next morning with a clear head :slight_smile:

I had and still have sometimes the same thing, that I look hours for some complicated solution while there is an easy way and when I see it I hit my forehead :wink: :smiley: But that's what a superb forum like this here is good for :slight_smile: