Scripts execution

hello everybody:
i think this is really quite of dummy question.
after I write a new script, and give it the execute permission.
some times its just enough to call its name to run the script , other times I need to include ksh or ./ScriptName .
so how I can make all my scripts run by just calling their names only.

hope i managed to made it clear
thanks alot

Include your current directory in PATH environment variable

PATH=$PATH":."

do one thing
give full execute permission and copy this file into /usr/local/bin or /usr/bin so that u can execute and see this command script anywhere

Do this (copy it to a dir which is already in your PATH) instead of anbu23's solution. That's a little bit dangerous.

if the script is for specific purpose other than root , grials suggestion can be use d to copy file to home directory and set the PATH variable

PATH=$PATH:/home/(anyhome directory)
export $PATH

using this also can ease your work

Do you have the hash-bang on the first line?

e.g. #! /bin/ksh

This tells the shell that the file contains korn script and it will automatically execute it with ksh.

So rather than:

> ksh ./somescript.ksh

you can use:

> ./somescript.ksh

This assumes that ksh is in /bin and somescript.ksh has execute permissions.

Also - be careful about arbitrarily adding other paths to your PATH variable. Just because it makes it easier doesn't make it better. I never have the current directory on the PATH - my preference is more safety over the hassle of typing ./

HTH

thanks for all your replies guys.
I added the hash bang thing but didnt solve the issue.
I wasnt into adding the path thing, what i did is i added .ksh to the ScriptName.
so now its name is: test.ksh instead of test.
and it worked.
thanks again

Well, there's your problem. Don't name it "test". "test" is a real binary.

:frowning:

Thx alot Glenn Arndt. I should have mentioned it from the begining.

how can I tell if the script name is valid or reserved for the system??

Thx

For the most part, "which binary" should help. This won't catch everything, though. For example, you might (unknowingly) have "f" aliased to "ls -alF". If you name your script "f", the alias "f" would be interpreted before the script "f".

Probably the most popular way to avoid having your script names interfering with existing binaries is to use some variation of ".sh" as a suffix.