How to use cygwin to run bash script

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to use cygwin to run bash script
# 1  
Old 04-27-2008
How to use cygwin to run bash script

Hi, all,

I try to run a quite simple bash script in cygwin, it's content is:


echo "It is my first bash shell"

there are three lines in the script. The second line is blank line.

When I run it use command: bash c:/,
I got error " command not line 2:", I wonder if it is not allowed to have a blank line in bash script.

Another question is when I run it use command ./c:/, I got error "bash: ./c:/ no such file or directory. " but I think we can run script by ./filename, is that right?

I am a novice of Unix and cygwin, any help would be appreciated.

# 2  
Old 04-27-2008
i've never used cygwin... but what is about the path to the shell? is it /bin/bash in this case? i think all you have to deal with is a path issue. maybe it's better to install a linux or use a live cd (ubuntu for exampel) and test your scripts in a complete linux/unix environment...

good luck,

Last edited by DukeNuke2; 04-27-2008 at 06:44 PM..
# 3  
Old 04-27-2008
The garbled error message looks like you have DOS line terminators when you should have Unix ones (although I would have imagined Cygwin would be pretty much immune to such issues).

The error message is basically "./pretty/long/path/to/ line 2: (carriage return): command not found", only the carriage return causes the text after it to be printed back at the left margin, overwriting the beginning of the error message.

DOS uses the sequence carriage return + line feed to terminate lines, whereas Unix wants just a line feed.

Blank lines in scripts are not a problem, but see if you can find an editor which allows you to see any control characters, and perhaps remove or replace them.

If ./myscript works for you, then by all means use that. The weird masking which Cygwin has to do to make the file system appear Unix-like is rumored to cause gray hairs. (I never used it much, either.)

Last edited by era; 04-27-2008 at 06:45 PM.. Reason: Explain error message garbling
# 4  
Old 04-27-2008
Thanks for your replies.

Yes, I do use a winXP os. Maybe I need to run it on real unix system. It seems like there is no a easy way to run it on windows.
# 5  
Old 04-27-2008
Don't be so pessimistic, thousands of people run Cygwin every day, you just need to get used to it and figure out the quirks.
# 6  
Old 04-27-2008
Thanks, era.

I find a way to fix it. Save it in UltraEdit from dos to unix style.

Thank you for your help. I was too pessimistic.
# 7  
Old 04-28-2008
Originally Posted by Jenny.palmy
... I find a way to fix it. Save it in UltraEdit from dos to unix style. ...
This can also be done in vim by using
:set ff={dos,unix,mac}

-- see Change end-of-line format for dos-mac-unix - Vim Tips Wiki - a Wikia wiki ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using BATCH to call a BASH script on CygWin

I am trying to use a batch file to automatically execute a bash script with no luck this far. The batch script looks like this: C:\Cygwin64\bin\bash I have also tried this: C:\Cygwin64\bin\bash "C:\Cygwin64\bin\" Needless to say that the windows box has Cygwin... (7 Replies)
Discussion started by: Xterra
7 Replies

2. Shell Programming and Scripting

Bash Script (tar + md) on Cygwin

Hi everybody, First, I'm sorry for my bad english! I have the following situation: I have a Windows 2012 R2 with Cygwin installed. The Windows Server is used as a backup Server with Dell AppAssure installed. At the moment, AppAssure saves Backup Targets to a repository on his D. The... (9 Replies)
Discussion started by: fibra3000
9 Replies

3. Shell Programming and Scripting

Cygwin bash script to unmount and mount an XP partition

As stated, I am looking into keeping my backup drive unmounted in normal windows use. Partly this is to address threats like cryptolocker. Since one of my backup drives is an internal drive, it will not likely afford any protection from such a threat. I am thinking of adding code to my rsync script... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

4. Windows & DOS: Issues & Discussions

run cygwin bash script from notepad++

I'm using Notepad++ to edit my BASH scripts and using CYGWIN to run them from Windows7. In Notepad++ there is a 'Run' capability. How do I get this to run my scripts directly without having to enter the script name from the Cygwin command line? (3 Replies)
Discussion started by: millsy5
3 Replies

5. Shell Programming and Scripting

How to run Cygwin bash from windows scheduled task?

Hmmm.... I love these forums because I always get great prompt responses and I want to ask a question about running bash on windows. Is that allowed? Now I know I can install cygwin cron and run bash that way. Can I run bash from windows schedule task? How? thanks siegfried (1 Reply)
Discussion started by: siegfried
1 Replies

6. Shell Programming and Scripting

BASH: Script jams Cygwin to 100% CPU -

I'd like to streamline the code more than a bit to get it to run faster. There's a thread about this and related issues of mine on the Cygwin mailing-list, but I want to eliminate any chances it might just be inefficient/inelegant/crappy code. A previous run of the same script on both Cygwin and... (6 Replies)
Discussion started by: SilversleevesX
6 Replies

7. UNIX for Dummies Questions & Answers

Cygwin bash script and read command

Hello everyone, I am struggling a bit with a batch script that I need to run in cygwin. I work in winXP and I had to write some awk scripts to do some file manipulation, and now I would like to automate the process by just running a batch file so that my colleagues can use it easily. Now, the... (2 Replies)
Discussion started by: Teroc
2 Replies

8. UNIX for Dummies Questions & Answers

tip: Simple script won't run in cygwin - vim editor involved

I ran into this issue and thanks to various postings in various forums, was able to figure out the solution but didn't see one posting that laid the whole issue out cleanly. So thought the following might help others ... ------------------------------------------------------------------------... (2 Replies)
Discussion started by: oxysep
2 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. Shell Programming and Scripting

how to run cgi -script on Cygwin ?

All, I would like to run a cgi script in cygwin which i have installed in WinXP. My CYGWIN directory structure is /var/www/ drwxrwx---+ 2 user Users 0 Nov 23 16:24 cgi-bin drwxrwx---+ 3 user Users 0 Oct 22 17:21 htdocs drwxrwx---+ 3 user Users 0 Oct 22 17:22 icons and another... (1 Reply)
Discussion started by: jambesh
1 Replies
Login or Register to Ask a Question

Featured Tech Videos