1,105,263 Community Members

Shell scripting in Cygwin

Member Avatar
java_programmer
Junior Poster
130 posts since May 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
0
 

I was trying to run a shell script and run it through Cygwin terminal in XP environment.
The script I have written is as follows -

#!/bin/bash
read -p "Enter Your name - " fname
if test "$fname" == "abcd"
    then
            echo "Thank you abcd"
fi

When I am trying to run it, after taking the input it gives an error -
': not a valid identifier: read: `fname
Though the commands are working fine when I am trying them in terminal.
Any suggession plz.
Thanks in advance...

Member Avatar
thekashyap
Practically a Posting Shark
809 posts since Feb 2007
Reputation Points: 193 [?]
Q&As Helped to Solve: 77 [?]
Skill Endorsements: 0 [?]
 
0
 

Try dos2unix on your script.. looks like there are ^M chars.. you must've edited the script using some Windows' app instead of `vi` or some unix app..

Not that you can't use Windows app.. just be careful in setting up the preferences in the editor to ensure it saves in correct format..

Member Avatar
java_programmer
Junior Poster
130 posts since May 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks. I have solved problem already...

Try dos2unix on your script.. looks like there are ^M chars.. you must've edited the script using some Windows' app instead of `vi` or some unix app..

Not that you can't use Windows app.. just be careful in setting up the preferences in the editor to ensure it saves in correct format..

Member Avatar
JeoSaurus
Posting Whiz in Training
227 posts since Sep 2008
Reputation Points: 32 [?]
Q&As Helped to Solve: 36 [?]
Skill Endorsements: 0 [?]
 
0
 

I wonder what the solution was? :)
I haven't used cygwin in a while. I'm curious to know what the problem was!

Member Avatar
java_programmer
Junior Poster
130 posts since May 2006
Reputation Points: 0 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
1
 

It is a special character related problem. I used notepad++ editor to write the script initially, which adds some special character not supported by linux. You can either use dos2unix to convert it into linux format or just use cat > filename to create the file. Then you can edit the file in windows based editor as well.

I wonder what the solution was? :)
I haven't used cygwin in a while. I'm curious to know what the problem was!

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article