Hi,
Can anybody tell me how to error trap an empty line. If i am asked for a password and I hit enter without entering any text, how do i display an error?
Thanks
Kev
Hi,
Can anybody tell me how to error trap an empty line. If i am asked for a password and I hit enter without entering any text, how do i display an error?
Thanks
Kev
Try this...
#!/bin/ksh
echo "Enter passwd : \c"
read passwd
if test ! -n "$passwd"
then
echo "Please enter something"
fi
So how would i go about puting it into this:
echo "Which User ID do you want to check?"
read user
grep $user /etc/passwd
if test $? -eq 0
then
echo "$user exists"
else
echo "$user is available"
fi
exit 0
Cheers
I couldn't figure out what you need exactly
sorry,
I meant how to put the error trapping into the script. I need the script to return an error if enter is pressed and no data has been entered.
That's exactly the script I gave does. Try running the script and Just press eneter when it prompts for the passwd. It will display the message!!
Try this !
echo "Which User ID do you want to check?"
read user
if test ! -n "$user"
then
echo "Please enter something"
exit 1
fi
grep $user /etc/passwd
if test $? -eq 0
then
echo "$user exists"
else
echo "$user is available"
fi
exit 0