LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-22-2004, 03:02 AM   #1
Beppe83
Member
 
Registered: Mar 2004
Posts: 41

Rep: Reputation: 15
Cygwin and Bash????


I did a bash script with Cygwin under Windows.

When I open it in Linux Mandrake and I type:

./file.sh

It says:

bad file or interpreter : no such file or directory

So I create a new file .sh from an editor inside Linux, everything goes ok...

I'm confused...
 
Old 06-22-2004, 05:16 AM   #2
Cerbere
Member
 
Registered: Dec 2002
Location: California
Distribution: Slackware & LFS
Posts: 799

Rep: Reputation: 33
Probably those pesky DOS carriage return / newlines. Try the following script (from the Advanced Bash-Scripting Guide):
Code:
Example 12-19. Du: DOS to Unix text file conversion.

   1 #!/bin/bash
   2 # Du.sh: DOS to UNIX text file converter.
   3 
   4 E_WRONGARGS=65
   5 
   6 if [ -z "$1" ]
   7 then
   8   echo "Usage: `basename $0` filename-to-convert"
   9   exit $E_WRONGARGS
  10 fi
  11 
  12 NEWFILENAME=$1.unx
  13 
  14 CR='\015'  # Carriage return.
  15            # 015 is octal ASCII code for CR.
  16            # Lines in a DOS text file end in CR-LF.
  17            # Lines in a UNIX text file end in LF only.
  18 
  19 tr -d $CR < $1 > $NEWFILENAME
  20 # Delete CR's and write to new file.
  21 
  22 echo "Original DOS text file is \"$1\"."
  23 echo "Converted UNIX text file is \"$NEWFILENAME\"."
  24 
  25 exit 0
  26 
  27 # Exercise:
  28 # --------
  29 # Change the above script to convert from UNIX to DOS.
You're going to have to remove the line numbers yourself (I'm too lazy), and by the way, the exercise at the bottom is optional ;-)

Enjoy!
--- Cerbere
 
Old 06-22-2004, 06:39 AM   #3
Beppe83
Member
 
Registered: Mar 2004
Posts: 41

Original Poster
Rep: Reputation: 15
THANKS!

This helped me! Now the script works under Linux too!!!

THANKS AGAIN MAN!
 
Old 06-23-2004, 02:24 AM   #4
Cerbere
Member
 
Registered: Dec 2002
Location: California
Distribution: Slackware & LFS
Posts: 799

Rep: Reputation: 33
My pleasure. You might also do a google search for 'dos2unix'. It'll find a bunch of programs and a really elegant perl script for doing the same thing.

Enjoy!
--- Cerbere
 
Old 06-23-2004, 03:54 AM   #5
cck23
Member
 
Registered: Jun 2004
Location: Surrey, UK
Distribution: Mandrake 10 Download
Posts: 73

Rep: Reputation: 16
Hi

I don't know if this helps but I have always converted DOS files that have the pesky ^M character using the following:

sed 's/^M//' olddosfile > newfilename

(Note: ^M = CTRL V, then M. Dont let go of CTRL)

This seems to me a lot easier than above, but maybe there is something that the script would do that the above sed script wouldn't do? I'd like to know if that is the case

On another note, Beppe83, did you fix your "sort" problem that you posted elsewhere?


CK
 
Old 07-12-2004, 11:01 AM   #6
wirawan0
Member
 
Registered: Aug 2003
Location: Virginia, USA
Distribution: Mandrake 9.1, SuSE 9.2, Ubuntu 7.04-10.04, Sabayon 5, Debian 6
Posts: 64

Rep: Reputation: 18
Or, even simpler:

tr -d '\r' < file.dos > file.unix

for file.dos being the DOS text file to be converted. This will strip ALL carriage returns, which means that at rare occassion it isn't desirable. The best thing would be:

sed -e 's|\r$||' < file.dos > file.unix

These should be run under bash. Other shells may or may not work. Always check first with a test file.
 
  


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
why use cygwin? curos Linux - Newbie 8 11-05-2005 07:45 PM
Cygwin help Whipl50 Linux - General 0 05-12-2005 03:57 PM
help with cygwin Devbmx Linux - Newbie 19 09-24-2004 11:45 AM
Cygwin anyone?? vickr1z Programming 1 09-23-2004 02:13 PM
Cygwin:How do you turn the bash shell bell off? petercool Linux - Newbie 8 05-23-2003 10:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:34 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