Subject: Re: Problem Executing Scripts
From: Christopher Faylor <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Wed, 8 Nov 2000 16:56:15 -0500

On Wed, Nov 08, 2000 at 04:50:18PM -0800, Jeffrey Gruen wrote:
>Recently, I downloaded Cygwin-b20 (cygwin-1.1.4.tar) for WindowsNT.

Where did you get the impression that this was "Cygwin-b20"?  This
is Cygwin 1.1.4.  It has nothing to do with B20.

>It has been working just fine until today when we tried to write some
>very simple scripts to run.  Below is one such script that runs
>beautifully on a dec alpha UNIX machine, but will not run in Cygwin for
>NT:
>
>#this little script makes back-up of files in a directory
>for file in *
>do
>cp $file $file.bak
>done
>
>So far, we have discovered:
>1. How to make the file executable in Cygwin (by adding .exe to the end,
>since "chmod" does not seem to work very well)
>
>2. That the "*.exe" file must to be in the bin folder in order to run
>
>3. That bash crashes if we make the first line of the script "#!/bin/sh"
>
>(We even tried running:  "echo '#!/bin/sh' > script.exe; ./script", but
>this did not work either).
>
>Please help.  How can a make a script file that runs flawlessly in UNIX
>run in Cygwin, as well.  The ability to write and execute small scripts
>like this would save me much time!

As you have discovered, Windows does not have an 'execute bit', so you
cannot just put some commands in a file, do a 'chmod -x file' and then
'./file'.

Well, actually you can.  If you are using an NTFS filesystem, then
setting the CYGWIN environment variable to 'ntsec' (do this prior to
running any cygwin program) will allow you to set the executable bit.
The "NT security" model allows you to use full UNIX permissions on
your files.  It only works on NT, though.

The usual way to make your scripts executable is by adding a '#!/bin/sh'
to the beginning of them.  Don't give the scripts a '.exe' extension.
That will cause Windows to try to execute them as Windows executables
rather than scripts.

To execute the file, it has to be located in a directory referenced
by your PATH environment variable.  The current directory "." is not
located in your PATH by default.  You'll have to add it if you want
to execute files in your current directory without typing "./file".

One esoteric way to give a script or a directory executable permission
is to use the mount command:

mount -x -b c:\cygwin\bin /bin	# cygwin gives everything in /bin
				# the 'executable' bit

mount -x -b c:\cygwin\bin\foo /bin/foo # cygwin gives /bin/foo the
				       # executable bit

Most of the above should be located in the Cygwin FAQ.  I would suggest
that you read this and the other documentation available at
www.cygwin.com so that you don't have to "figure out" stuff in the
future.

cgf

--
Want to unsubscribe from this list?
Send a message to [email-masked]