#!/bin/bash
while echo -n \"Player\'s name?\"
read name
[ $name != \'ZZZ\' ]
do
searchresult=$(grep [$name] playername)
if [ $searchresult = 0 ]
the
It would REALLY HELP if you include a sample of the data in the three files you're using 'grep' on!
You've misunderstood what the
variable=$(command)
operation does. The '$()' operation assigns the standard output of the command to the variable, not the exit code of the command. If you want to use your original script, with the exit code, try this instead:
grep [$name] playername > /dev/null 2>&1
searchresult=$?
The '=' operator in 'test' (also known as '[ ]') is for strings. You really want to use the '-eq' operator instead, which is for integers.
Without the data, I can't really figure out what the rest of the script should look like. As it is, it really looks strange to me.
Since you're using bash, I can make a suggestion for improving your input checking.
target=UnSeT
while [ $target = "UnSeT" ]
do
read -p "if See target (T/t) or team name (M/m)?" target
case "$target" in
[Tt]) target="T";;
[Mm]) target="M";;
*) target="UnSeT"; echo "Please enter T or M.";;
esac
done