0
#!/bin/bash

while echo -n "Player's name?"
    read name
    [ $name != 'ZZZ' ]

do
searchresult=$(grep [$name] playername)
if [ $searchresult=0 ]

then

    echo -n "if See target (T/t) or team name (M/m)?"

    read team
    read target

    while [ [ $target!=T ] || [ $team!=M ] ]

        do

        echo "Please enter only T or M."
        done

        if $target=T
        then
            grep [ $name ] targetselected

        else

            grep [ $name ] teamselected

        fi

else

echo 'no such player'

fi

done
echo You are now exited search

error msg - line 10: [: too many arguments, what is that mean?

3
  • you should put read inside the while, otherwise your while could never return false, since it does the same thing everytime? Commented Feb 10, 2014 at 2:47
  • it'd be helpful if you pointed out where line 10 is, coz line 10 in the above is a blank line. Commented Feb 10, 2014 at 2:55
  • thanks, line 10 is if [ $searchresult=0 ] Commented Feb 10, 2014 at 3:24

2 Answers 2

0

Not sure which line 10 in posted code you are pointing to but I found few issues with your posted code as

the line while [ [ $target!=T ] || [ $team!=M ] ] should be

while [ $target!="T" ] || [ $team!="M" ]

Also, if $target=T should accordingly be if $target="T"

Sign up to request clarification or add additional context in comments.

Comments

0

The two lines:

searchresult=$(grep [$name] playername)
if [ $searchresult=0 ]

are very wrong. If you are trying to determine if the grep succeeds, it is best to do:

if grep -q "$name" playername; then ...

Putting grep in $() and assigning to searchresult has you comparing the output of grep rather than checking its exit status. And the spaces that are missing around the = in the second line are very wrong. Assuming searchresult is a string that contains no whitespace and only alphanumeric characters, the line if [ $searchresult=0 ] will always evaluate to true because the string "$searchresult=0" is always non-empty. (If searchresult is the empty string then $searchresult=0 is the string =0 which is non-empty, so the test succeeds.) It is highly unlikely that you intend to be testing whether or not that string is empty. The exact error that you are seeing indicates that the grep is assigning a value to searchresult which contains whitespace. In that case [ $searchresult=0 ] (without double quotes around $searchresult) is being parsed by [ as multiple arguments (split on the whitespace in $searchresult), and the error is telling you that there are too many arguments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.