Running shell script in Cygwin terminal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running shell script in Cygwin terminal
# 1  
Old 02-25-2012
Running shell script in Cygwin terminal

I am new to shell scripting.
I tried to run a simple shell script using Cygwin terminal in Win XP env.
The script I have written is as follows -

Code:
#!/bin/bash
a=5
[[ "$a"== "5" ]] && echo "true" || echo "false"

But when I execute the script, getting some confusing error. The error I am getting are -
Code:
first_prog.sh: line 2: $'\r': command not found
first_prog.sh: line 4: $'\r': command not found
first_prog.sh: line 5: conditional binary operator expected
first_prog.sh: line 5: syntax error near `"5"'
first_prog.sh: line 5: `[[ "$a"== "5" ]] && echo "true" || echo "false"'

Though the commands are working fine individually when run from terminal, but not in the shell script. Do I need any settings in the Cygwin terminal?
I am using the BASH shell.
Please suggests.
Thanks in advance.

Last edited by Franklin52; 02-26-2012 at 05:16 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 02-25-2012
Are you editing this script with notepad? This will fill the file with garbage carriage returns which the shell will consider as part of shell statements, ruining them. Try 'dos2unix' to fix the script.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 02-26-2012
One thing I noticed is that there seems not to be a space between the double equal in the test and the "5" (hard to see without code tags).

Code:
#!/bin/bash
 a=5
 [[ "$a" == "5" ]] && echo "true" || echo "false"
#       ^ Need space here

Corona688's concerns still apply, but this is certainly causing issues too.

Last edited by agama; 02-26-2012 at 12:36 AM.. Reason: typo
This User Gave Thanks to agama For This Post:
# 4  
Old 02-26-2012
Thanks Corona and Agama, yes both were the problem.
Once I converted to unix format using dos2unix, I identified the other problem as well. Now it is working fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Running Powershell Script from Linux through Cygwin

Hello Experts, I am creating a run time powershell script on Linux machine and copying that powershell script to Windows machine. To connect to windows through "ssh", I am using Cygwin tool. To make the connection password less I copied my public in authorized_keys in windows Administrator... (5 Replies)
Discussion started by: shekhar_4_u
5 Replies

2. Programming

Running python script in cygwin

I have python installed here on windows: C:\Python27 and can run a script from the command line but would rather use cygwin. $ cd "C:\Users\cmccabe\Desktop\annovar" cmccabe@DTV-L2231M5J /cygdrive/c/Users/cmccabe/Desktop/annovar $ python run_batch_job.py Traceback (most recent call last):... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Running q-shell commands( on IBM-i Series) from cygwin terminal (on windows)

I have cygwin installed on windows server and when I do echo $SHELL the output is /bin/bash I have created a ssh tunnel from this windows server through cygwin to ibm -i series which is running Q-shell. I am trying to invoke a utility wsadmin (used for scripting) on ibm-i from the... (12 Replies)
Discussion started by: gaurav99
12 Replies

4. Shell Programming and Scripting

Cygwin shell script

I have a file with below format : 2013-05-20 hello has done 2013-05-20 hi 000abc abc 2013-05-21 thank you I want the out put to be like this : 2013-05-20 hello has done 2013-05-20 hi 000abc abc 2013-05-21 thank you What I could think of is something like this : cat... (7 Replies)
Discussion started by: Sparta
7 Replies

5. Shell Programming and Scripting

script does not close terminal after running

For a small script i want it so that the terminal closes when the script has completed its tasks. To do so i use at the end if the script the following: echo "Hello, World!" echo "Knowledge is power." echo "" echo "shutting down terminal in 10 seconds" exit 10 however the terminal stay's... (3 Replies)
Discussion started by: Ditzyken
3 Replies

6. OS X (Apple)

[Solved] Running shell code in AppleScript without Terminal

What I want my script to do is to run a command in Terminal and close that same Terminal window when the process is complete. Of course I could ad a delay of 6 seconds to complete the process, but it may not be enough every time. To simplify my question, this is what I want to achieve.... (9 Replies)
Discussion started by: ShadowofLight
9 Replies

7. Shell Programming and Scripting

Cygwin-shell script

hi, I am using Cygwin for running the shell script. If i execute the following command at the prompt output is obtained. grep echo * The same i have put in a file and when am trying to execute it is throwing error. IP.sh echo "Starting command..........." grep echo * ... (9 Replies)
Discussion started by: flamingo_l
9 Replies

8. UNIX for Dummies Questions & Answers

Problems running script on remote Terminal

Hi, I'm new here so please excuse any stupidity that occurs in my post :P My situation: Have a java program which I have to run a ridiculous amount of times and put the output data into a text file. Thought the easiest way to do this would be to delve into the world of scripts. I am at home... (1 Reply)
Discussion started by: lozyness
1 Replies

9. Shell Programming and Scripting

running terminal with script

suppose we have a file ab 81 and another file exec < $1 while read line do ssh root@172.16.1.$line done while running the command sh file.sh ab output display as shown Pseudo-terminal will not be allocated because stdin is not a terminal. root@172.16.1.81's password: after... (3 Replies)
Discussion started by: cdfd123
3 Replies

10. Shell Programming and Scripting

Running a script without a terminal session

I'm trying to figure out how I can run a script "myScript.sh" in such a way that if my remote network connection gets disconnected, the script doesn't stop functioning. Right now I log in, run "./myScript.sh" and watch my output get pumped to a log file for about 10 hours. Only problem is that... (3 Replies)
Discussion started by: jjinno
3 Replies
Login or Register to Ask a Question