-3

I am writing a script that will automatically work with MySQL. I do not understand how to implement this:

MYSQL_RESULT=mysql -u LOGIN -pPASS -D "TABLE_NAME" -e "SQL request";
for i in $MYSQL_RESULT; do
    if [ $i -le 100 ]
        then r_kills = '100';

    elif [ $i -le 500 ]
        then r_kills = '100';

    elif [ $i -le 1000 ]
        then r_kills = '500';

    echo $r_kills;
    fi
done;
sh: 21: cron.rankme.sh: r_kills: not found
Biffen
  • 6,249
  • 6
  • 28
  • 36

1 Answers1

0

This is an invalid assignment. You may not have spaces in front of or behind the equal sign in the shell - in contrast to most programming languages I know:

if [ $i -le 100 ]
        then r_kills = '100';

if [ $i -le 100 ]
        then r_kills=100;

Note that there isn't a way to distinguish numbers and text in the shell, either. Single- and double quotes are only used to mask special characters, including whitespace.

The message

sh: 21: cron.rankme.sh: r_kills: not found

mislead me to think, you used something which is not in the path, but in reality, the tokenizer had decided, that r_kills = '100' is a programm call to r_kills with two parameters, '=' and '100'.

The first line - without knowing mysql very well,

MYSQL_RESULT=mysql -u LOGIN -pPASS -D "TABLE_NAME" -e "SQL request";

most probably has to be

MYSQL_RESULT=$(mysql -u LOGIN -pPASS -D "TABLE_NAME" -e "SQL request";)

or

MYSQL_RESULT=($(mysql -u LOGIN -pPASS -D "TABLE_NAME" -e "SQL request";))

to create an array, since you try to iterate over the variable.

user unknown
  • 35,537
  • 11
  • 75
  • 121