Re: [SLUG] Bash Script

From: Eben King (eben1@tampabay.rr.com)
Date: Sun May 29 2005 - 10:47:37 EDT


On Sun, 29 May 2005, Paul M Foster wrote:

> On Sat, May 28, 2005 at 10:31:20PM -0400, 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.

Doing a "save as" counts as creation usually. Sometimes looking at it with
a particularly rude Windows editor does too.

> Better, find a hex editor or something that will look at the file in hex.

vim 6.1.165 will -- look for "[dos]" in the lower left corner -- and so will
od:

[eben@pc eben]$ od -t x1z testfile
                    vv vv vv vv vv vv
0000000 74 68 69 73 0d 0a 69 73 0d 0a 61 0d 0a 74 65 73 >this..is..a..tes<
0000020 74 0d 0a 66 69 6c 65 0d 0a >t..file..<
           ^^ ^^ ^^ ^^
0x0d=CR
0x0a=LF

If they come in pairs, you have a DOS text file.

> Actually the "less" command should do this.

My version of less:

[eben@pc eben]$ less -V
less 358+iso254

doesn't show the format.

> The reason is this: under DOS, a line termination is carriage return and
> then linefeed.

Back in the days of teletypes, at the end of each line, the print head had
to be sent back to the beginning of the line, and the paper had to be
advanced one line. The order didn't matter. But to save time, a Carriage
Return (CR) was sent to tell the print head to return to the left, and while
it was on its way (slow), a Line Feed (LF) was sent to advance the paper
(fast).

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

-- 
-eben    ebQenW1@EtaRmpTabYayU.rIr.OcoPm    home.tampabay.rr.com/hactar
GEMINI:  Your birthday party will be ruined once again by your explosive
flatulence. Your love life will run into trouble when your fiancee hurls a
javelin through your chest.  -- Weird Al, _Your Horoscope for Today_

----------------------------------------------------------------------- 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:25:10 EDT