cygwin executable shell scripts

Hello,

Cygwin will execute a shell script without turning on executable status on the file.

I want to force cygwin to be more like linux and not execute scripts directly on the command line unless changing mode to have executable status.

Is this possible?

Thanks

Larry

This is because you do not have a shebang on the first line of the script. bash calls exec to run the file, the first thing it does is to get the interpreter from the script. When there is none it behaves differently. In effect: it does not execute the script it reads it.

A shebang is

#! [interpreter file name like /bin/bash /usr/perl] 

The #! goes in the leftmost column (column one) of line one.
ex:

#!/bin/sh
# code goes here ....

This uses the default shell. In cygwin this is bash.

Thank you very much Jim, that does work.

But this is still different behavior than a more traditional linux/unix release. Because typically when not putting the shebang in a script then the shell you are running will be used to execute it, and like you explain it will fork & exec but you will still get a permission denied without +x being on.

I am new to cygwin, but I know for example in RedHat with or without shebang it will not run directly without +x on the file.

This will work for the purposes of using cygwin to teach shell scripting, but that behavior is not typical. I will just make sure I add the #! to illustrate the different ways to execute a shell script

Larry