What is the difference between executing script using Cygwin and PuTTY?

0

Now I get a script.sh, previously it was executed using PuTTY provided it was written in VMWare, but now I want to execute in Windows using Cygwin, I already copy the script.sh out to the corresponding directory, but some commands Cygwin can not recognise.

generate(){
 date +%T
}

TIME = generate()
echo " Current Time: $TIME"

After execute in Cygwin

script.sh: line 3: syntax errot neat unexpected token '$'<\r''
script.sh: line 3:'generate<><

Lily

Posted 2011-03-18T03:22:13.213

Reputation: 21

Answers

1

You have a couple of errors in your script. You can't have spaces around the equal sign in an assignment. In order to assign the output of a function or program to a variable, you have to use command substitution which means the command name is surrounded by $() (which is preferable) or backticks (which is less desirable). Also, when you call a function, you don't use parentheses after the function name like you would in other languages.

generate () {
    date +%T
}

TIME=$(generate)

echo " Current Time: $TIME"

The $'\r' error comes from having Windows line endings. You can use dos2unix to convert the file or use an editor that you can choose which type of endings to save a file with.

dos2unix script.sh

Paused until further notice.

Posted 2011-03-18T03:22:13.213

Reputation: 86 075

I still new in shell script, this troubles me when i follow a linux shell script book, it always execute in Linux environment but i try it in Windows, so there are problems appear. Thank you very much for your help – Lily – 2011-03-18T06:33:41.850