LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Command not found error (https://www.linuxquestions.org/questions/linux-newbie-8/command-not-found-error-905353/)

greenpool 09-28-2011 02:14 AM

Command not found error
 
Hi,

i'm attempting to run the following script but i've been presented with errors i'm not familiar with. can some please point out whats wrong, thanks!


script:
Code:

#!/bin/bash
#Purpose: syslog like logging for our scripts

$MYDATE=`date "+%b %d %T"`
$MYHOST=`hostname`
$MYSCRIPT=`basename $0`

$MYMESSAGE="Successful"


echo "$MYDATE $MYHOST $MYSCRIPT $MYMESSAGE"


error:


Code:

=Sep: command not found
=ubuntu: command not found
No command '=bash' found, did you mean:
 Command 'bash' from package 'bash' (main)
 Command 'rbash' from package 'bash' (main)
=bash: command not found
=Successful: command not found


Nylex 09-28-2011 02:16 AM

You need to get rid of the dollar signs in the assignment statements. You only use $ when you want to get a variable's value. You might also consider replacing the backticks with $(). For example,

Code:

$MYDATE=`date "+%b %d %T"`
should be

Code:

MYDATE=$(date "+%b %d %T")

David the H. 09-28-2011 08:04 PM

See here for why $(..) is highly recommended over `..`

By the way, basename can be replaced with a built-in parameter expansion.

Code:

MYSCRIPT="${0##*/}"
bash also already sets a default HOSTNAME shell variable for you.


All times are GMT -5. The time now is 02:59 AM.