Re: [SLUG] Bash Script

From: Paul M Foster (paulf@quillandmouse.com)
Date: Sun May 29 2005 - 02:18:42 EDT


On Sat, May 28, 2005 at 10:31:20PM -0400, Bob Stia wrote:

> On Wednesday 25 May 2005 21:27, Eben King wrote:
> > On Wed, 25 May 2005, Bob Stia wrote:
>

<snip>

> I put a set -x above and a set +x below and this is what i got:
> ----------------------------------------------------------------
> Running /home/bob/commands/ImageMagickConvert
>
> /home/bob/commands/ImageMagickConvert: line 34:  
> : command not found
> /home/bob/commands/ImageMagickConvert: line 35:  
> : command not found
> /home/bob/commands/ImageMagickConvert: line 36:  
> : command not found
> /home/bob/commands/ImageMagickConvert: line 37:  
> : command not found

Bob:

There's a really serious anomaly here. As you run this, you're a
"command not found" error on lines 34 through 37. But here's the
problem: if you count down, some of those lines contain nothing, so
there's no reason you should be getting that error. Moreover, if the
error was occurring on lines where there's actual code, you shouldn't
get that error but a different one. And the set +x would give you a

some_command: command not found

rather than just

: command not found

I just ran a test on something. Check to see if this file was created
under DOS or Windows. Better, find a hex editor or something that will
look at the file in hex. Actually the "less" command should do this.
Just type:

less /home/bob/commands/ImageMagickConvert

or whatever the name of the script is. If you see some stuff in there
that looks like this:

^M

then the file was created under DOS and will not run properly under
Linux. In fact, you may well get exactly the error you're getting. The
reason is this: under DOS, a line termination is carriage return and
then linefeed. Under Mac, a line termination is just a carriage return.
Under Linux and Unix, it's just a linefeed. When Linux/Unix sees a
carriage return in certain places in a script, it gets confused. I won't
explain why unless you just want to know. Suffice it to say, it's a
problem.

Do what I said above and let us know if the file contains those ^M
(carriage return) characters.

Paul
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 19:24:01 EDT