Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 04-25-2009, 07:18 PM   #1
LQ Newbie
Registered: Mar 2004
Location: Broomfield, Colorado, USA
Distribution: Ubuntu
Posts: 9

Rep: Reputation: 0
Issues copying script file from windows to linux and running


I was working on some shell scripts for a VMWare server I've inherited (I'm not a linux admin... yet) and had some strange behavior going on.

I was writing the shell scripts on my windows machine in Notepad++ and then copying the script files over to the linux VM server. Whenever I would go to execute the script, it wouldn't work right. What I mean is that I would get errors for unknown commands, seemingly like the script was only running part of the commands on the line.

An example is if I had a line with "clear" on it, the script appeared to be only running "cle" and then throwing an error saying "unknown command cle".

Is this common when moving files from windows to linux? I rewrote the script from scratch using Vi in the SSH session and everything worked fine.

Is there a special way to save files on windows so they don't have problems in Linux? Script files are obviously nothing but plain text, so I'm not sure what was happening.
Old 04-25-2009, 08:12 PM   #2
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
One issue is that Windows tends to use "\r\n" (carriage-return line-feed) at the end of each line, while Linus (and other *nixes) use simply "\n". I think Notepad++ should have a setting to save in the appropriate format, somewhere in the preferences (I know that Notepad2 does).

If you open the files in vi, you are likely to see that they have "^M" at the end of each line. Entering the following command should solve the problem:
:1,$ s/<Ctrl-V><Ctrl-M>//
By Ctrl-V I mean (of course) "hold down the Ctrl key and press V" (likewise with M) - This will enter a "^M" character. 1,$ addresses every line from first to last.

Hope this helps.
Old 04-25-2009, 08:14 PM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
A windows editor adds carriage returns after newlines. You can run "dos2unix" on the script to convert it. You can also install cygwin and an editor like vi locally.


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
BASH Shell script : copying a file to multiple folder zamri Programming 14 04-29-2008 10:27 AM
To write a script file to check the running exe in LINUX platform udhaya Linux - Newbie 1 01-31-2008 08:13 AM
file copying issues with bash Furlinastis Programming 3 05-03-2006 01:32 AM
copying a file from windows nt to slax linux distro mrobertson Linux - General 2 05-23-2005 10:20 PM
copying linux file to windows workstation shadowsurfer Linux - Networking 3 09-17-2004 09:54 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:23 AM.

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