Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help - Running a script without using 'sh' command.

Status
Not open for further replies.

brent01

Technical User
Jul 11, 2001
32
GB
I have written a simple script that works, but I have to use the command sh <script> to run it. Just typing in the script name does not work.

Is there a way of executing the script by just typing the script name?

Thanks.
 
Yes, there is.

Put the following as the first line of the script.

#!/bin/sh

That should run the script in a Bourne Shell, regardless of your current shell.

I hope that helps.

Mike
 
Thanks Mike. I tried that, but I still get the same error - 'bash: restart: command not found' or 'restart: not found'

Any other ideas?
 
Make sure that your script is executable.
 
I've done an ls -l and the permissions are -rwxrwxrwx so I think it is executable.
 
You most likely, then, do not have "." in your PATH. You should be able to run it as "./restart" if you're in the directory of the script.

You probably don't really want to have the script be world-writable, by the way.
 
Hi brent01,

Did the script work when you tried:
sh <script>

The error you mentioned ("bash: restart: command not found' or 'restart: not found") indicates a script called 'restart' cannot be found (I don't think it is a built-in command in BASH). As has already been suggested, check you PATH variable or use the full path when calling it.

As an aside, to help troubleshoot a script and pin-point the line that causes a problem, try:
sh -x <script>


I hope that helps.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top