Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

 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<><
share|improve this question

1 Answer 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


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
share|improve this answer
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 Mar 18 '11 at 6:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.