LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-21-2013, 03:01 AM   #1
waddles
Member
 
Registered: Sep 2012
Posts: 372

Rep: Reputation: 1
Unziping & moving(mv) a .sh file to user directory is adding(?) ^M to file lines


When I unzip a file and give the file executable permission and run it, I get:
axel.sh: /bin/bash^M: bad interpreter: No such file or directory
I examined the file with vim and see no ^M anywhere. I tried to search on that and got pattern not found.
The retaining directory (user) is: drwxr-xr-x
The /bin/bash file shows the same size for ls -lt, ls -lc, & ls -ltu
The ls -ltu does show today's date but that is access time.
The other options for ls have dates of 2011 and 2012.
Anyone know of my stupid dog trick I did to myself?
 
Old 11-21-2013, 03:17 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Maybe the file has been created in Windows and ^M is a shortcut for the sequence \r\n, that is the carriage-return/newline used by Windows as line terminator. In vim you can see them by typing the command
Code:
:e ++ff=unix
and you can remove them by means of
Code:
:set fileformat=unix
then write and quit. In alternative you can try the linux command:
Code:
$ dos2unix axel.sh
Hope this helps!
 
1 members found this post helpful.
Old 11-21-2013, 03:18 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,945

Rep: Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325
vim recognizes ^M automatically and will hide it.
You can use the command file to check if it has ^M chars.
Also you can use od -xc <filename> to look into it.
 
2 members found this post helpful.
Old 11-21-2013, 03:34 AM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by waddles View Post
When I unzip a file and give the file executable permission and run it, I get:
axel.sh: /bin/bash^M: bad interpreter: No such file or directory
It is important to note that it is not the act of unzipping and making it executable that adds the offending EOL character, those are already in the file.
 
Old 11-22-2013, 12:32 AM   #5
waddles
Member
 
Registered: Sep 2012
Posts: 372

Original Poster
Rep: Reputation: 1
I agree with astrogeek & pan64 that is the normal situation. Not here tho.
I checked the unzipped file with vim after unzipping. NO ^M's.
After chmod +x axel.sh and run then I get:
bash: ./axel.sh: /bin/bash^M: bad interpreter: No such file or directory
I again check it with vim and again not ^Ms.
That is why I checked /bin/bash because it said "bad interpreter" and from #1 the size is consistent.
I can run other scripts so unless it is seeing something before it executes that is not in other scripts the interpreter is OK.
I could reinstall the bash interpreter but don't think that is a solution due to no ^M following the inspection and knowing EOLs are not showing up.
PAN64 --THANKS!!
I did run UR suggestion.
It appears it was built under dos BUT vim did not show carriage return and new line.
Had not had this problem when unzipping this file before so this was the surprise. Strange.

Last edited by waddles; 11-22-2013 at 12:47 AM.
 
Old 11-22-2013, 01:08 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,945

Rep: Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325Reputation: 7325
Hm. I never told you that is the normal situation. Have you tried od -xc? I do not think bash itself is not ok, I still think there is a problem in your file, the first line contains some "strange" chars after the h.
 
Old 11-22-2013, 01:54 AM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
Quote:
Originally Posted by waddles View Post
I agree with astrogeek & pan64 that is the normal situation. Not here tho.
Well, I assure you that...
Quote:
Unziping & moving(mv) a .sh file to user directory is adding(?) ^M to file lines
... is not happening (unless maybe you are running Ballmer Linux ).

The odd characters are in the file. And I agree with pan64, your bash is OK, it would be silly to reinstall.

What is the output of

Code:
file axel.sh

od -xc axel.sh
Or could you open it in vim and convert to hexadecimal

Quote:
:%!xxd
... and post the first couple of lines.

The ^M's may not be visible in vim depending on configuration, so don't get hung up on the fact that you didn't see them.

Last edited by astrogeek; 11-22-2013 at 01:56 AM.
 
1 members found this post helpful.
Old 12-13-2013, 05:37 PM   #8
perbh
Member
 
Registered: May 2008
Location: Republic of Texas
Posts: 393

Rep: Reputation: 81
As everybody else has pointed out - the 'CR' is allready there - it has _not_ been caused by unzipping/moving.
Also, bash and vi (and many others for what I know) silently ignores the 'CR'. If you had run:
Code:
sh axel.sh
you probably would've been ok.

Here's a li'l example:
Code:
echo -e "#!/bin/bash\necho \"hello world\"" >test.sh
cat test.sh | sed -e 's/$/\r/' >test-2.sh    # ie making it into a dos-file
chmod a+x test-2.sh
sh test-2.sh ==> hello world
./test-2.sh  ==> /bin/bash^M: bad interpreter: No such file or directory

cat test-2.sh | tr -d '\r' >test-3.sh    # which brings us back to the original ...
All the test*.sh looks _exactly_ the same in 'vi' unless you use the appropriate switches
 
1 members found this post helpful.
  


Reply



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
Adding lines to each block in a multicolumn text file stevanity Linux - Newbie 8 06-12-2014 01:51 AM
Adding lines of a file together buee Linux - Newbie 2 02-22-2010 08:17 PM
Little help unziping a file Asagath Linux - Desktop 1 08-11-2006 11:41 AM
adding text to lines in a file tpreitano Linux - General 2 10-04-2005 09:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:51 PM.

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