LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-16-2007, 12:46 PM   #1
eublade
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Rep: Reputation: 0
crlf-cr conversion


i downloaded some program source (cvscedega) from windows and then copied to my root folder.
when i try and execute the install scripts, it tells:
/bin/bash^M unknown interpreter
i guess this should be caused by having saved the files from windows, using crlf as carriage return
i kind of remember there should be some command to do this windows-to-linux conversion for ascii files, can someone tell me please?
 
Old 08-16-2007, 01:00 PM   #2
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
dos2unix, but that's probably not your problem. Check the execution parameters:
ls -l install-script

If it doesn't have an exec bit set (no x in the xwrxwrxwr area) then you need to do something like:
chmod a+x install-script
OR
chmod 750 install-script

-Chad
 
Old 08-16-2007, 02:05 PM   #3
sudhach
LQ Newbie
 
Registered: Aug 2007
Posts: 5

Rep: Reputation: 0
Won't work, bash won't honor ^M.

run a onle liner

dos2unix < install-script > install-script.sh
or
perl -ne 's/\s+$//g; print $_."\n"' < install-script > install-script.sh


then run the script like this

sh install-script.sh

Last edited by sudhach; 08-16-2007 at 02:08 PM. Reason: Typo
 
Old 08-16-2007, 02:05 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I don't have the answer, but I would not think that the error message ("/bin/bash^M unknown interpreter") would be caused by the execute permission being off.
 
Old 08-16-2007, 02:22 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by sudhach View Post
perl -ne 's/\s+$//g; print $_."\n"' < install-script > install-script.sh
Wouldn't that cause a double-spaced output ???.
Each line will still have the LF after deleting the CR, so why add \n ???.

No harm probably ...

I use sed to do similar.
 
Old 08-16-2007, 02:33 PM   #6
sudhach
LQ Newbie
 
Registered: Aug 2007
Posts: 5

Rep: Reputation: 0
Nope.

As \s+$ removes any white space at the end of the line(meaning removes all of CR, LF, Tab, Vertical Tab...).

the "\n" adds just the LF
 
Old 08-16-2007, 06:47 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Ahh - yeah, I just lop off the last char rather than al the whitespace.

cheers ...
 
Old 08-16-2007, 07:07 PM   #8
maroonbaboon
Senior Member
 
Registered: Aug 2003
Location: Sydney
Distribution: debian
Posts: 1,495

Rep: Reputation: 48
Minimal unix solution:

$ tr -d '\015' < infile > outfile

(\015 = octal 13 = ascii ^M).
 
Old 08-17-2007, 12:19 PM   #9
eublade
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Original Poster
Rep: Reputation: 0
thanks for the answers, i'll try and see
this is not very comfortable though cause i don't know how many scripts there are, if too many i better just redownload anything from linux...

i was trying with another thing:
i copied the cvs folder to my shared fat partition, then i mounted it with:
mount -t vfat -o conv=a /dev/sda3 /shared_fat
in the mount man page, it says that conv=a for (v)fat enables the crlf<->lf conversion at driver level for ascii files. then i cp -r the folder to my home but they're all still dos-encoded.
i even tried conv=t which should translate every file, but neither did anything, strangely enough...
 
Old 08-17-2007, 06:21 PM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Presuming you want to change every line of everything called .sh in the current directory, something like the following should work
Code:
for i in `ls *.sh` ; do sed -i 's/.$//' $i ; done
Substitute any of the options offered above depending on taste. Likewise the glob can be modified to suit.
 
Old 08-17-2007, 06:27 PM   #11
eublade
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Original Poster
Rep: Reputation: 0
if they had .sh extension it'd be easy
instead there're a lot of scripts without any extension, that's why i tried with the vfat auto conversion, if it worked like it's supposed to do

well i'll try and convert every file recursively, they should be all ascii files so no harm

Last edited by eublade; 08-17-2007 at 06:42 PM.
 
Old 08-17-2007, 06:49 PM   #12
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
"for i in `ls *`" ???
If it's going to hit things I don't want hit I just create a test directory with the things that need fixing, and splat that. Then move them back.

There's usually a way.
 
Old 08-18-2007, 11:03 AM   #13
eublade
LQ Newbie
 
Registered: Aug 2007
Posts: 18

Original Poster
Rep: Reputation: 0
ok i've done it
i've written this script to change only text files and to reset the x attribute for the rewritten files:

Code:
#!/bin/bash
#copies every file recursively from $FROM_DIR to $TO_DIR
#converts all text files from DOS convention to UNIX convention (CRLF->LF)
#by Eugenio

FROM_DIR="/root/bin/winex_dos/"
TO_DIR="/root/bin/winex/" #previous content will be deleted before conversion

# returns OK if $1 contains $2
strstr() {
  [ "${1#*$2*}" = "$1" ] && return 1
  return 0
}

convert() {
  test -d "$2" || mkdir "$2" || ! echo "Unable to create destination folder $2" || exit 1
  for entry in $(ls -Ap "$1"); do
    if [ -f "$1$entry" ]; then
      $(strstr "$(file "$1$entry")" "text") && $(perl -ne 's/\s+$//g; print $_."\n"' < "$1$entry" > "$2$entry")
      $(strstr "$(file "$1$entry")" "executable") && $(chmod +x "$2$entry")
    elif [ -d "$1$entry" ]; then
      $(convert "$1$entry" "$2$entry")
    fi
  done
}

test -d $TO_DIR || mkdir $TO_DIR || ! echo "Unable to create destination folder $TO_DIR" || exit 1
test -r $FROM_DIR || ! echo "Unable to read from source folder $FROM_DIR" || exit 1
test -w $TO_DIR || ! echo "Unable to write to destination folder $TO_DIR" || exit 1

rm -fr $TO_DIR
cp -r $FROM_DIR $TO_DIR
convert $FROM_DIR $TO_DIR

exit 0
thanks to everybody for the help

Last edited by eublade; 08-18-2007 at 12:07 PM.
 
  


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
SQL Query to remove CRLF SimonT Programming 3 02-11-2007 05:05 PM
bitpim conversion tribeone Linux - Software 0 02-09-2007 02:18 PM
Changing coding of text file(LF -> CRLF) koyi Linux - General 2 10-18-2005 07:44 AM
Javascript: Converting newlines into actual CRLF scuzzman Programming 2 08-25-2005 11:52 PM
Total Conversion? guy Linux - Hardware 4 11-25-2003 06:54 PM

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

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