LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find out what is causing command not found in script (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-out-what-is-causing-command-not-found-in-script-711584/)

debicool 03-14-2009 09:54 AM

How to find out what is causing command not found in script
 
I have a very small script which queries a mySQL table and puts the result into a variable. Actually that is what I want to do.

When I just run the mysql command on the command line it works fine.
Put into the script and run the script the script returns the result plus has at the end the command not found as well.
see below... 23 is the actual result from the query but what is causing the command not found at the end?

./myscript.sh: line 4: 23: command not found

How can I figure out what is causing that.

Below my code
#!/bin/sh
#

sqlcount= `mysql --host=host --user=user --password=apassword --silent --skip_column_names -e"SELECT count(*) as Users_Logged_On FROM user_logon u WHERE logon_state='Logged On' and LOGON_DT >= curdate();" aDatabase`

echo $sqlcount

pwc101 03-14-2009 09:56 AM

Assigning a value to a variable is as follows:
Code:

val=1
valnext=something

Remove the space between the = and your backticked command:
Code:

#!/bin/sh
#

sqlcount=`mysql --host=host --user=user --password=apassword --silent --skip_column_names -e"SELECT count(*) as Users_Logged_On FROM user_logon u WHERE logon_state='Logged On' and LOGON_DT >= curdate();" aDatabase`

echo $sqlcount

Your error was that the output of your mysql command was 23, which sh was trying to execute as a command, which it couldn't.


All times are GMT -5. The time now is 11:55 AM.