LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   BASH Script - command not found!! (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-command-not-found-687469/)

JavaNinja 12-01-2008 09:31 AM

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

acid_kewpie 12-01-2008 09:45 AM

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.

JavaNinja 12-01-2008 09:52 AM

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?

colucix 12-01-2008 10:10 AM

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?

JavaNinja 12-01-2008 10:15 AM

Quote:

Originally Posted by colucix (Post 3360585)
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 (Post 3360585)
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. :)

colucix 12-01-2008 10:20 AM

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.

JavaNinja 12-01-2008 10:26 AM

Quote:

Originally Posted by colucix (Post 3360603)
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.

colucix 12-01-2008 10:30 AM

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).

JavaNinja 12-01-2008 10:35 AM

Haha Genius! :)

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

Thank you very much!

JavaNinja 12-01-2008 10:37 AM

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!

colucix 12-01-2008 11:09 AM

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


JavaNinja 12-01-2008 11:35 AM

Ah ok, I see. Thank you once again! :)

colucix 12-01-2008 11:45 AM

You're welcome! :)


All times are GMT -5. The time now is 04:09 PM.