LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-08-2017, 03:15 AM   #16
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 748

Rep: Reputation: 323Reputation: 323Reputation: 323Reputation: 323

The \r shouldn't be there at all!!!

Try: dos2unix <demo.sh >newdemo.sh
chmod 755 newdemo.sh
./newdemo.sh

How are you creating the files? vi? M$Win editor?

Sorry, I don't have a better explanation of the difference between Unix \n and Dos CRLF
Maybe like: https://forms.na1.netsuite.com/app/s...en-using-putty
or: https://stackoverflow.com/questions/...ress-enter-key

p.s. Your use of [CODE tags is PERFECT, so you don't need that termbin.

Last edited by !!!; 11-08-2017 at 03:31 AM.
 
Old 11-08-2017, 03:30 AM   #17
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,492

Rep: Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532
no, I have already posted that script works properly for me.
One reason can be the ^M which must be removed from your script.
You can see a lot of \r in your od -c result, that is exactly the same issue.
run dos2unix on your script to fix it (install this tool if not found)
 
2 members found this post helpful.
Old 11-08-2017, 03:48 AM   #18
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 748

Rep: Reputation: 323Reputation: 323Reputation: 323Reputation: 323
>"two different, unrelated issues."
>"exactly the same issue."


Can someone help me with my:
>"better explanation of the difference between Unix \n and Dos CRLF"
? Thanks!!!
 
Old 11-08-2017, 03:54 AM   #19
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,492

Rep: Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532Reputation: 5532
Quote:
Originally Posted by !!! View Post
>"two different, unrelated issues."
>"exactly the same issue."
^M and \r are exactly the same things, but not related directly to the "unexpected end of file".
 
1 members found this post helpful.
Old 11-08-2017, 04:44 AM   #20
Anna$9
LQ Newbie
 
Registered: Nov 2017
Posts: 24

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by !!! View Post
>"two different, unrelated issues."
>"exactly the same issue."


Can someone help me with my:
>"better explanation of the difference between Unix \n and Dos CRLF"
? Thanks!!!
Yea thanks ,It worked
 
Old 11-08-2017, 04:55 AM   #21
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,493

Rep: Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107Reputation: 4107
CRLF i.e. carriage return linefeed dates back to the typewriter days. In a nutshell the carriage mechanism was a cylinder that held the paper. Pushing the carriage lever once would move it back to the beginning of the line and a second press of the lever would advance the paper to the next line. cr is represented as a 13 or 0d hex (ASCII code), control+m (^M) and as a \r in many languages. The linefeed is represented as a 10 or 0a hex (ASCII code) or \n in many languages.

Different operating systems use different codes for representing a new line. unix and and unix like systems use LF only and MS Windows uses the CR+LF.

https://en.wikipedia.org/wiki/Newline

Last edited by michaelk; 11-08-2017 at 05:13 AM.
 
1 members found this post helpful.
Old 11-08-2017, 08:33 PM   #22
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873Reputation: 873
Quote:
Originally Posted by Anna$9 View Post
I have already posted this,this is a simple if/else statement that does not work in a Linux VM.
Implying that it does work on bare metal? Perhaps it's an issue with your VM software, not the script.
 
Old 11-08-2017, 10:05 PM   #23
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,741

Rep: Reputation: 790Reputation: 790Reputation: 790Reputation: 790Reputation: 790Reputation: 790Reputation: 790
\n is the Unix newline (also named LF or line feed),
but your file has \r\n that is MS DOS newline.
Unix/Linux sees the \r (also named ^M or CR or carriage return) at the end of the lines.
The cat command does not print the \r. (But cat -v prints it.)
Even vim (or vi if aliased to vim) does not show them, instead prints a little hint ("DOS" or similar) in its status line.
You must remove the \r at the end. You can use the dos2unix command for that, or (GNU-)sed in Linux
Code:
sed -i 's/\r$//' filename
The $ is the line end and the preceding \r character is substituted with nothing i.e. deleted.
 
Old 11-08-2017, 11:45 PM   #24
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 748

Rep: Reputation: 323Reputation: 323Reputation: 323Reputation: 323
Quote:
Originally Posted by Shadow_7 View Post
Implying that it does work on bare metal? Perhaps it's an issue with your VM software, not the script.
Naw, OP accidentally suspected whatever was 'nearby'. VBox is trueUtopia.

@OP=Anna$9, glad you fixed it! Please mark Thread as solved (link at top of page)
(so LQgurus can learn my1990Unix)

Just curious: @OP: was some M$editor creating the demo.sh file? ?? ??? Yes? (&dos2unix fixed it?)
(so future readers &LQgurus can know...)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script to cause wifi scan get "unexpected end of file" message Ed1952 Linux - Software 5 11-27-2015 09:39 AM
[SOLVED] why wont my code work, " syntaX error: unexpected end of file" jsf1337 Linux - Newbie 5 03-01-2015 11:23 AM
[SOLVED] Script returning with error "syntax error: unexpected end of file" n_raghuvanshi Linux - Software 4 08-25-2013 08:49 AM
[SOLVED] Shell Scripting "syntax error : unexpected end of file" roxie600 Programming 12 04-30-2010 12:18 AM
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration