Image

testing for empty strings

I'm programming something in bourne shell. I am not allowed to use any bash commands not in bourne.

Trying to do a check for empty string when a user enters an input, but for some reason it's not working. As long is it's an empty string, it keeps asking, but the second it's no longer an empty string, it fails.

search_name=""
while [ expr $search_name != [a-zA-Z]* ]; do
echo "Please enter the player's name: \c"
read search_name
done


Now, i did try the [ -n $search_name ] and had no luck in that sense either. I know the above is searching through the file system, but my docs show that it should be checking the input has at least one of the characters in the string.

The other problem is that I'm supposed to look through a database file and only search a certain set of character positions. so -c12-26; it semi works, because when it goes through, it seems to be reformating my text and ends up searching elsewhere in the database file.

while read line; do
names=`echo $line|cut -c12-26`
if echo $names | grep -i -q $search_name; then
echo "$names\t$line"
fi
done < $database


Any ideas as to why the above would not work?