1753770 Members
4666 Online
108799 Solutions
New Discussion юеВ

Re: script problem

 
hp-ux_2
Occasional Advisor

script problem

Hi Guys,
when i create a script name is "test", after creation when i run the script, it always run ./test. please tell me why i need to give ./ for running. i am a root user and created thru root user.
12 REPLIES 12
Bharat Katkar
Honored Contributor

Re: script problem

Becuse your script is not in the execution path.
You either copy your script "test" in /usr/bin or add path of your test script to PATH.

# export PATH=$PATH:

This way you don't have to specify ./

Hope that helps.
Regards,
You need to know a lot to actually know how little you know
Pete Randall
Outstanding Contributor

Re: script problem

Check your path: "echo $PATH"

Most likely $PATH does not contain "." (your home directory). For the root user, this is deliberate, as putting "." in root's PATH is considered a security risk.


Pete

Pete
Steve Steel
Honored Contributor

Re: script problem

Hi


put it in /usr/contrib/bin or /usr/local/bin

But then everybody can get it.

Otherwise give it a meaningful name and use the alias command to set the short name = fullpathname


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
john korterman
Honored Contributor

Re: script problem

Hi,

when you write "test", and do not get any error message, you actually execute a (standard) program named test.
"test" is normally located in /usr/bin and probably in yout path; therefor you do not get errors.
It is of course confusing to use a name like that.


regards,
John K.
it would be nice if you always got a second chance
Mark Nieuwboer
Esteemed Contributor

Re: script problem

Hi,

If you want to start the script in the directory where it stand you need ./ to exucute ./ stand for current directory.
If you just want to start the script int has to stand in the directory which stand in PATH. You can see al these directory's by echo $PATH.

p.s. please give pionts to the one who helped. try to make it 29 0f 29 instead of.
I have assigned points to 8 of 29 responses to my questions.
H.Merijn Brand (procura
Honored Contributor

Re: script problem

Worse even: for some shells, 'test' is a builtin. It is used before $PATH is searched.

Another bad idea is to make 'test' an alias or a shell-function :)

# which test

might give you that info

Enjoy, Have FUN! H.merijn
Enjoy, Have FUN! H.Merijn
Ralph Grothe
Honored Contributor

Re: script problem

I was wondering why no one was mentioning what a bad name test is for a shell script until I read the so far final remark by procura.
This reminds me of the very amusing rants of Damian Conway in his Perl Best Practices about unintelligent, unimaginative, lazy, lousy, poor, and evil variable names ;-)
Madness, thy name is system administration
Steven E. Protter
Exalted Contributor

Re: script problem

Shalom,

best practices:

Always do the ./scriptname thing when testing a new script. Recall a problem I once had where scp would not work because an application venderput its own script on the path with the name scp.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Howard Marshall
Regular Advisor

Re: script problem

I will agree with the statement that "test" is not a good name for a script. The program "test" is what "[" is linked to inside many shell scripts but sometimes the actual program test is called and if it calls your script the output will be different causing a random running of your script and a difficult to troubleshoot failure of the other script.

When you are developing a new script you can put it in a new subdirectory and add . as the first line in your PATH variable so it will search your current working directory first.

If in doubt use the which command to see if another program or script is in your path before the one you want.

H