cygwin executable shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cygwin executable shell scripts
# 1  
Old 09-01-2012
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
# 2  
Old 09-01-2012
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
Code:
#! [interpreter file name like /bin/bash /usr/perl]

The #! goes in the leftmost column (column one) of line one.
ex:
Code:
#!/bin/sh
# code goes here ....

This uses the default shell. In cygwin this is bash.
# 3  
Old 09-01-2012
Thank you

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Programming

CYGWIN executable crash ??

Ok I feel kind of stupid asking since it's been a while since I used an UNIX system but here goes. I recently installed the full CYGWIN on my Windows 7 machine. Seem like a nice package. So to test it out I did the basic hello world deal. It compiles just fine. But when I run it it crashed :(. So I... (4 Replies)
Discussion started by: g8rmark
4 Replies

3. UNIX Desktop Questions & Answers

creating an executable file from shell scripts

Hi Friends, I have a shell script which does some operations etc, would it be possible to create an executable file out from this shell script? meaning the executable file is not editable, thus the source code will not be visible to other users for copyright reasons. Please help, thanks! (1 Reply)
Discussion started by: kokoro
1 Replies

4. UNIX for Dummies Questions & Answers

Help with sorting executable files in shell

Hi!I'm new in this forum,also in shell scripting! :P I'd like to help me with an issue!the project wants to make a variable with a directory(any) and then print all executable files of this directory,sorted by size!Thank you! (8 Replies)
Discussion started by: strawhatluffy
8 Replies

5. Shell Programming and Scripting

[SHELL] Executable? Run it!

I would like to make a script that I can see if the file is executable. If it is executable then it needs to run. Otherwise, if it is not executable the file needs to be edited, and run agian. I hope you understand what i mean. :) Thanks for the netherlands (4 Replies)
Discussion started by: dennisbest85
4 Replies

6. 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

7. Shell Programming and Scripting

> in cygwin scripts

I'm using cygwin under WinXP. When I write things like ls > list.txt in shell, it works OK. But when I place it to file like this: It says that "list.txt" doesn't exists. I tried touch, but the answer is the same. (2 Replies)
Discussion started by: TeenageWerewolf
2 Replies

8. Shell Programming and Scripting

Need to call an Executable (.exe) using shell

Hi all , I need to call an executable (.exe) using shell script. Actual need is i need to call that shell script and do an export of some tables is there any way . the executable is datamover Please let me know if there are any option !! (2 Replies)
Discussion started by: raghav1982
2 Replies

9. Shell Programming and Scripting

Can't get Cygwin to run scripts

I haven't been on a unix system in a long time and I'm trying to teach a friend unix. After looking at/testing various options cygwin seemed to be the easiest to download and install. Everything works pretty much as I recall and I even tested a small java program on it. I can't seem to get... (4 Replies)
Discussion started by: mmtemp
4 Replies

10. UNIX for Dummies Questions & Answers

Cygwin shell not coming up

Hi, I installed Cygwin y'day on Win XP SP2. The install went fine but when I clicked on Cygwin's shortcut to invoke its shell, it didn't come up.....was just opening for a fraction of second and then closed. Can anyone please advise? Regards er_ashu (6 Replies)
Discussion started by: er_ashu
6 Replies
Login or Register to Ask a Question