KItis
KItis

Reputation: 5626

Running Linux Shell script on windows environment

I have been trying to run Linux shell script on Windows machine. to run the script on windows environment, i have selected Cygwin.

when i first started running the script using cygwin, i first faced following issue.

line 12: $'\r': command not found

but line number 12 does not have any command

  08  #
  09  ######################################################################
  10  #### PARAMETERS TO SET BEGIN
  11  ######################################################################
  12  
  13  # archive setttings
  14  ARCHIVE_USER=abc                      # archive storage user name  (default)
  15  ARCHIVE_GROUP=app                     # archive storage user group (default)
  16  ARCHIVE_PATH=/test/file               # archive storage directory (default)
  17  ARCHIVE_DELAY=+8

To solve this issue used dos2unix command and generated new shell scrip from the old one

when i run this newly generated scrip it again returns an error

housekeeper.sh: 2: Syntax error: newline unexpected

following is the dos2unix generated script.

>#!/bin/bash
>>#
>># Date  : 2012-03-22 (yyyy-mm-dd)

could somebody explain me what is wrong with the line number2 here.

thanks in advance for any help

Following is top of the script i am trying to run , this is the script i get after converting using dos2unix command

>#!/bin/bash
>>#
>># Date  : 2012-03-22 (yyyy-mm-dd)
>># Modified by   : ABC
>># Goal          : Draft version for X house keeping environment
>>#
>># Description : This script perform housekeeping of XYS products.
>>#
>>######################################################################
>>#### PARAMETERS TO SET BEGIN
>>######################################################################
>>
>># archive setttings
>>ARCHIVE_USER=user1                               # archive storage user name (default)
>>ARCHIVE_GROUP=gapp                              # archive storage user group (default)
>>ARCHIVE_PATH=/product/file                        # archive storage directory (default)
>>ARCHIVE_DELAY=+8                              # archive files older than delay (in days)
>>
>># purge setttings
>>PURGE_DELAY=+30                                   # purge files older than delay   (in days)

Upvotes: 1

Views: 2121

Answers (2)

Graham
Graham

Reputation: 1749

It also looks as if your script has a ">" at the beginning of every line.

That doesn't work.

Your first line needs to be #!/bin/bash, not >#!/bin/bash.

To remove the leading '>' characters, try the following command:

sed -i.bak 's/^>*//' housekeeper.sh

(assuming your script is named housekeeper.sh).

This will make a backup copy of your script with a .bak extension, and remove all leading greater-than signs from each line in the file.

Upvotes: 2

trojanfoe
trojanfoe

Reputation: 122381

That sounds like a line termination issue (Windows uses Carriage Return, Linefeed and Unix uses just Linefeed). You can correct these issues using dos2unix (and unix2dos), which converts the line terminators.

Try:

$ dos2unix myscript.sh

Upvotes: 2

Related Questions