Page 1 of 1

bash not taking <CR><LF>

Posted: Mon Sep 05, 2016 12:00 am
by quarkjuggler
I created a script under windows and moved it to RPi. bash kept giving "sytax error: unexpected end of file". Using hd, I discovered that lines ended with <CR><LF> rather than <LF>. Is there an easy way to fix this? Thanks.

Re: bash not taking <CR><LF>

Posted: Mon Sep 05, 2016 12:14 am
by kusti8

Re: bash not taking <CR><LF>

Posted: Mon Sep 05, 2016 2:35 am
by quarkjuggler
Command not found. However, my linux mint said to "sudo apt-get install tofrodos", which I did on the Pi. It looked for all the world like it was installing, but I still don't find the command.

Meanwhile, I was trying this:

Code: Select all

tr -d \015 <build2.sh >build3.sh
I don't understand why this doesn't work. The output has retained the hex 0d. Did I goof up the syntax? man tr says to give a set of characters, so I tried surrounding \015 with [] and {}. Still no luck.

Re: bash not taking <CR><LF>

Posted: Mon Sep 05, 2016 3:28 am
by quarkjuggler
I got it with 'tr'! I had to put quotes around the \015 . Thanks for the
BTW, thanks for the instructions for getting Chrome browser set up on the pi. It's miles better than the epiphany browser.

Re: bash not taking <CR><LF>

Posted: Mon Sep 05, 2016 7:05 am
by DougieLawson
sudo apt-get install dos2unix works on Raspbian.

Re: bash not taking <CR><LF>

Posted: Mon Sep 05, 2016 5:35 pm
by quarkjuggler
Got it! Thanks. I shall never trust linux mint again.

Re: bash not taking <CR><LF>

Posted: Mon Sep 05, 2016 11:12 pm
by jbudd
There's a trick in Bash which comes in handy with files containing the DOS CR/LF:
Normally <ENTER> (the Enter/Return key) signals the end of the current command and Bash tries to execute it. But <CTRL>v<ENTER> prevents this.

So you can get rid of the unwanted characters with this

Code: Select all

sed -e s/<CTRL>v<ENTER>// filename > filename.new
As you type it, <CTRL>v does not show on the screen, the following <ENTER> shows as "^M"

Re: bash not taking <CR><LF>

Posted: Wed Sep 07, 2016 3:23 am
by quarkjuggler
jbudd wrote:

Code: Select all

sed -e s/<CTRL>v<ENTER>// filename > filename.new
There's that sed & awk stuff again! I worked at bash a bit but I haven't learned those two mammoth utilities yet. Fortunately, I can copy the characters onto my screen. Thanks, jbudd!

Re: bash not taking <CR><LF>

Posted: Wed Sep 07, 2016 8:29 am
by jbudd
There's that sed & awk stuff again! I worked at bash a bit but I haven't learned those two mammoth utilities yet.
The only computer book I have ever sat down and read from cover to cover is Aho, Kernighan & Weinberger - The AWK Programming Language.
1988 - those were the days!

Re: bash not taking <CR><LF>

Posted: Wed Sep 07, 2016 4:15 pm
by DougieLawson
jbudd wrote: The only computer book I have ever sat down and read from cover to cover is Aho, Kernighan & Weinberger - The AWK Programming Language.
1988 - those were the days!
Wouldn't that be: Aho, Weinberger & Kernighan or did the language get renamed from AKW to AWK?

I quite enjoyed one of Brian Kernighan's other publications, done in collaboration with Dennis Ritchie, I learned a programming language from that one.

Re: bash not taking <CR><LF>

Posted: Thu Sep 08, 2016 10:18 am
by jojopi
DougieLawson wrote:Wouldn't that be: Aho, Weinberger & Kernighan or did the language get renamed from AKW to AWK?
That book is credited as A, K, W.
I quite enjoyed one of Brian Kernighan's other publications, done in collaboration with Dennis Ritchie, I learned a programming language from that one.
I very much liked one of Aho's other collaborations, The Dragon Book. It covers every language!

Re: bash not taking <CR><LF>

Posted: Fri Sep 09, 2016 6:32 am
by cheez
Another way to fix your CR+LF / LF problem, without needing to install anything additional, Raspbian comes with Leafpad. Open your script in Leafpad, do Save-as, at the bottom of the Save-as window you can select LF, CR+LF, or CR. In your case, select LF. Save file; done.

This feature can also be used if you want to take a file from GNU/Linux to MS Windows. Take your GNU/Linux file with the default LF, and save it with CR+LF, and now it will look right in Windows' Notepad.