Discuss Executing sh script ./ style in the Linux Help forum on Dev Shed. Executing sh script ./ style Linux Help forum discussing topics including usage, troubleshooting, modules, and distributions. Linux is an open source OS, based on UNIX.
Posts: 24
Time spent in forums: 3 h 58 m 32 sec
Reputation Power: 0
Executing sh script ./ style
I've been looking around the net for help on executing a shell script.
My basic understanding is that after setting executable permissions and providing a path (#!/bin/sh) in the first line of the script, I can type ./myscript to execute instead of sh myscript.
This is not working for me. I can run "sh myscript" but not "./myscript" even though I know for sure I have across the board execute permission and my sh path is correct.
I'm working on a redhat linux station. Can anybody point out what my problem is?
Posts: 14,233
Time spent in forums: 1 Month 4 Weeks 14 h 11 m 5 sec
Reputation Power: 4445
Redhat defaults to using bash not sh
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
Posts: 2,107
Time spent in forums: 1 Month 1 Week 1 Day 3 h 57 m 31 sec
Reputation Power: 1485
The shebang line (the #!/bin/sh as the first line in a script) just tells the system which interpreter this file is for. Where the script file you wish to run is found is another matter - that is handled by the $PATH environment variable and by how you invoke the script.
By using ./myscript you are telling the system you want to execute the file called myscript which is in the current directory. If it's elewhere it won't be found. Using sh myscript tells the system that you want to load the sh interpreter (which it should find!) then have that load and run the file myscript which, I think, will be searched for in the directories specifed in $PATH.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
Posts: 24
Time spent in forums: 3 h 58 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
What shell are you in? Or in other words, where are you trying to run the file from?
I'm in a tcsh environment.
@simon: Yes I'm in the same directory as the script i'm trying to run. But even so, when I try ./myscript I just get a "./myscript: command not found" error.
edit: Ok problem solved....turns out it was because I had started writing the script file on a windows machine so it had stupid windows invisible endline characters on it. Got rid of those and everything is good.
Posts: 2
Time spent in forums: 39 m 53 sec
Reputation Power: 0
If you want to use your shall file with different user either root . Give permission for your sh file execution according your need.
like that :
$ chmod ugo+rx file name