script problem (232 Views)
Reply
Occasional Advisor
hp-ux_2
Posts: 17
Registered: ‎01-15-2006
Message 1 of 13 (232 Views)

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.
Honored Contributor
Bharat Katkar
Posts: 2,309
Registered: ‎05-29-2003
Message 2 of 13 (232 Views)

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
Outstanding Contributor
Pete Randall
Posts: 16,205
Registered: ‎11-03-1996
Message 3 of 13 (232 Views)

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
Honored Contributor
Steve Steel
Posts: 2,909
Registered: ‎02-13-2000
Message 4 of 13 (232 Views)

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)
Honored Contributor
john korterman
Posts: 1,117
Registered: ‎11-15-2000
Message 5 of 13 (232 Views)

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
Esteemed Contributor
Mark Nieuwboer
Posts: 409
Registered: ‎08-06-2001
Message 6 of 13 (232 Views)

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.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,189
Registered: ‎10-13-1997
Message 7 of 13 (232 Views)

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
Honored Contributor
Ralph Grothe
Posts: 2,631
Registered: ‎04-09-2000
Message 8 of 13 (232 Views)

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
Exalted Contributor
Steven E. Protter
Posts: 33,806
Registered: ‎08-15-2002
Message 9 of 13 (232 Views)

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
Regular Advisor
Howard Marshall
Posts: 86
Registered: ‎09-26-2005
Message 10 of 13 (232 Views)

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
Regular Advisor
Howard Marshall
Posts: 86
Registered: ‎09-26-2005
Message 11 of 13 (232 Views)

Re: script problem

Oh yea. To answer your original question, the dot slash ./ is a relative path name where the dot . represents the current working directory as returned by the pwd command. The slash separates the directory from the filename of the script. So, if you change to the /usr/contrib/bin directory and execute /usr/contrib/bin/gzcat it would be the equivalent of ./gzcat sense . will translate to /usr/contrib/bin
Esteemed Contributor
Arturo Galbiati
Posts: 830
Registered: ‎02-10-2003
Message 12 of 13 (232 Views)

Re: script problem

Hi,
test is a ksh command so you have to use ./ to inform the shell that you want to execute your script and not the bulldin command.
rename your script as test.ksh and you can simple test.ksh to invoke it (if you have . in teh PATH).
HTH,
Art
Honored Contributor
RAC_1
Posts: 5,920
Registered: ‎03-21-2002
Message 13 of 13 (232 Views)

Re: script problem

first test is not a good name for the script. test is built in command for most of the shells.
Do following to know what exactly you will be executing.

type test

If you want to execute yout script names test, give full path when starting it.

/some_dir/some_dir/test
There is no substitute to HARDWORK
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.