User avatar
quarkjuggler
Posts: 156
Joined: Wed Nov 27, 2013 4:37 am
Location: Aransas Pass, Texas, U.S.A.

bash not taking <CR><LF>

Mon Sep 05, 2016 12:00 am

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.
Statements resembling facts are IMO only. "he" means "he or she", etc. "Mother Nature" is an abstraction, not a real spirit.
John

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: bash not taking <CR><LF>

Mon Sep 05, 2016 12:14 am

There are 10 types of people: those who understand binary and those who don't.

User avatar
quarkjuggler
Posts: 156
Joined: Wed Nov 27, 2013 4:37 am
Location: Aransas Pass, Texas, U.S.A.

Re: bash not taking <CR><LF>

Mon Sep 05, 2016 2:35 am

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.
Statements resembling facts are IMO only. "he" means "he or she", etc. "Mother Nature" is an abstraction, not a real spirit.
John

User avatar
quarkjuggler
Posts: 156
Joined: Wed Nov 27, 2013 4:37 am
Location: Aransas Pass, Texas, U.S.A.

Re: bash not taking <CR><LF>

Mon Sep 05, 2016 3:28 am

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.
Statements resembling facts are IMO only. "he" means "he or she", etc. "Mother Nature" is an abstraction, not a real spirit.
John

User avatar
DougieLawson
Posts: 36520
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: bash not taking <CR><LF>

Mon Sep 05, 2016 7:05 am

sudo apt-get install dos2unix works on Raspbian.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
quarkjuggler
Posts: 156
Joined: Wed Nov 27, 2013 4:37 am
Location: Aransas Pass, Texas, U.S.A.

Re: bash not taking <CR><LF>

Mon Sep 05, 2016 5:35 pm

Got it! Thanks. I shall never trust linux mint again.
Statements resembling facts are IMO only. "he" means "he or she", etc. "Mother Nature" is an abstraction, not a real spirit.
John

jbudd
Posts: 1025
Joined: Mon Dec 16, 2013 10:23 am

Re: bash not taking <CR><LF>

Mon Sep 05, 2016 11:12 pm

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"

User avatar
quarkjuggler
Posts: 156
Joined: Wed Nov 27, 2013 4:37 am
Location: Aransas Pass, Texas, U.S.A.

Re: bash not taking <CR><LF>

Wed Sep 07, 2016 3:23 am

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!
Statements resembling facts are IMO only. "he" means "he or she", etc. "Mother Nature" is an abstraction, not a real spirit.
John

jbudd
Posts: 1025
Joined: Mon Dec 16, 2013 10:23 am

Re: bash not taking <CR><LF>

Wed Sep 07, 2016 8:29 am

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!

User avatar
DougieLawson
Posts: 36520
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: bash not taking <CR><LF>

Wed Sep 07, 2016 4:15 pm

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.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: bash not taking <CR><LF>

Thu Sep 08, 2016 10:18 am

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!

User avatar
cheez
Posts: 13
Joined: Wed Mar 23, 2016 5:27 pm
Location: Iowa

Re: bash not taking <CR><LF>

Fri Sep 09, 2016 6:32 am

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.

Return to “Beginners”