LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-28-2011, 03:14 AM   #1
greenpool
Member
 
Registered: Sep 2010
Posts: 41

Rep: Reputation: 0
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
 
Old 09-28-2011, 03:16 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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")
 
1 members found this post helpful.
Old 09-28-2011, 09:04 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to compile C++ programs.make:g++ command not found error.Error 127 PrathuD Programming 3 03-16-2009 01:44 PM
error: Command Not Found dayalan_cse Programming 12 11-16-2006 12:59 AM
command not found error Deelk Slackware 12 04-23-2006 03:12 PM
command not found error cdsnithi Linux - Software 2 07-06-2005 01:26 PM
command not found error lordshipmayhem Linux - Newbie 4 06-28-2005 10:15 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration