LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-01-2008, 09:31 AM   #1
JavaNinja
Member
 
Registered: Sep 2008
Posts: 90

Rep: Reputation: 15
BASH Script - command not found!!


Hello all,

I get this error:
[root]# sh 87.sh filesToConvert.txt
: command not found
'7.sh: line 17: syntax error near unexpected token `{
'7.sh: line 17: `processLine(){

It refers to this part:

Code:
# User define Function (UDF)
processLine(){
  line="$@" # get all args

 START=$(date +%s)
	
  eval $line

#$line holds an ffmpeg command

END=$(date +%s)
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"

  echo $line
}
I am confused and new to Bash, help would be appreciated. I transferred the 87.sh to my server using filezilla. Does it need to be in ASCII mode?

Thanks all
 
Old 12-01-2008, 09:45 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
change it to
Code:
processLine()
{
  line="$@" # get all args
whitespace matters a lot more as bash isn't a programming language, just a series of individual commands which looks like one.
 
Old 12-01-2008, 09:52 AM   #3
JavaNinja
Member
 
Registered: Sep 2008
Posts: 90

Original Poster
Rep: Reputation: 15
Hi acid_kewpie. Thanks for the reply. I did as you said, now I get:

Code:
: command not found
'7.sh: line 17: syntax error near unexpected token `
'7.sh: line 17: `processLine()
Shall I remove all spaces around this area?
 
Old 12-01-2008, 10:10 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Two questions:
1) did you write the script on a Windows machine?
2) Can you give a real example of a call to the processLine function?
 
Old 12-01-2008, 10:15 AM   #5
JavaNinja
Member
 
Registered: Sep 2008
Posts: 90

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
Two questions:
1) did you write the script on a Windows machine?
Yes. Then I transferred the 87.sh to my server using filezilla, an ftp client.

Quote:
Originally Posted by colucix View Post
2) Can you give a real example of a call to the processLine function?
Do you mean this:

Code:
while read line
do
	# use $line variable to process line in processLine() function
	processLine $line
done
exec 0<&3
Thanks for the continued help guys.
 
Old 12-01-2008, 10:20 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Let's focus on the first question. If you wrote the script on a windows machine, then it may contain some weird character which is not managed by the shell. First try to run the dos2unix command:
Code:
dos2unix 87.sh
then try to run it again.
 
Old 12-01-2008, 10:26 AM   #7
JavaNinja
Member
 
Registered: Sep 2008
Posts: 90

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
First try to run the dos2unix command:
Code:
dos2unix 87.sh
then try to run it again.
I don't seem to have that command on my Fedora Core 7 server for some reason. However, I have looked through the script and there were no weird characters - is that enough?

A weird thing is if I run my script like ./87.sh i get the following:

Code:
-bash: ./87.sh: /bin/bash^M: bad interpreter: No such file or directory
But it runs fine with sh 87.sh - no idea what that means. I am doing all this as root.
 
Old 12-01-2008, 10:30 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
That's it. It is the "carriage return" plus "newline" character used by windows instead of the "newline" used by the unix systems. Most likely you don't see that sequence of character in your editor, but it's there. Check if you can install the dos2unix utility
Code:
yum install dos2unix
otherwise we will try another method (using sed).
 
Old 12-01-2008, 10:35 AM   #9
JavaNinja
Member
 
Registered: Sep 2008
Posts: 90

Original Poster
Rep: Reputation: 15
Haha Genius!

It worked, that is the most useful command ever for a windows/linux noob!

Thank you very much!
 
Old 12-01-2008, 10:37 AM   #10
JavaNinja
Member
 
Registered: Sep 2008
Posts: 90

Original Poster
Rep: Reputation: 15
Maybe a quick question if you are still arround.

I use eval for the lines I parse from the text file. It runs an ffmpeg command, is there a way I can supress the output of the command I call (ffmpeg)?

If its too much work, dont worry. I will just save the stuff I need to a text file!

Last edited by JavaNinja; 12-01-2008 at 10:38 AM.
 
Old 12-01-2008, 11:09 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Well, just use redirection. If you want to completely throw away the output, redirect it to /dev/null (and eventually the standard error as well) otherwise save it to a file, for example
Code:
eval blah blah blah > /dev/null 2>&1         # stdout and stderr lost
eval blah blah blah > file.log 2>&1          # stdout and stderr into file.log
 
Old 12-01-2008, 11:35 AM   #12
JavaNinja
Member
 
Registered: Sep 2008
Posts: 90

Original Poster
Rep: Reputation: 15
Ah ok, I see. Thank you once again!
 
Old 12-01-2008, 11:45 AM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome!
 
  


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
python script wont start - bash: myCommand : command not found owenm Linux - Newbie 2 11-06-2008 11:50 AM
Bash script says command not found - why? RavenLX Ubuntu 3 08-03-2007 02:19 PM
bash: rpm: command not found && sudo: alien: command not found Java_Code Ubuntu 7 07-27-2006 11:57 PM
Trying to write a bash script -- :Command not found? bpottle Linux - Software 7 06-10-2006 06:11 PM
Bash Script; command not found twintornado Programming 2 06-01-2005 09:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:16 PM.

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
Open Source Consulting | Domain Registration