Operating System - HP-UX
1836456 Members
2606 Online
110101 Solutions
New Discussion

question from a beginner..

 
Bernard Chan
Occasional Advisor

question from a beginner..

Hi to all HP-UX expert,

i would like to know y sometimes in the command prompt i need to type #./xxx to run the program or file...but sometimes no need...how can i direct run the program without the ./ command??
9 REPLIES 9
Animesh Chakraborty
Honored Contributor

Re: question from a beginner..

Hi,
#./xxx means that xxx is in your current directory and the path is not set.

If the command you are typing
is in your path then no need to type ./xxx
Did you take a backup?
Rajeev  Shukla
Honored Contributor

Re: question from a beginner..

Hi,
This is because your you dont have the current path set in your profile. If you set the PATH=$PATH:. in your profile and have execute permission for the file then you should be eable to run without ./..

Thanks
Rajeev
Michael Tully
Honored Contributor

Re: question from a beginner..

As stated, you need to have the program or script in your path to be able to run it without './'
It is not always possible to have a path set to every conceivable thing, and it is not a good idea anyway.

The general way to have this done is in the users .profile file. What this does is add the directory paths to the defaults. See /etc/profile and /etc/PATH
e.g
PATH=$PATH:/usr/local/bin:/admin/scripts
export PATH

This can also be done from the command line.


Anyone for a Mutiny ?
Philip Chan_1
Respected Contributor

Re: question from a beginner..


If the command you're running is searchable in the path variable (output of "echo $PATH") then you don't need the leading "./". Otherwise you have to run the command by specifying its exact path. By giving the leading "./" in front you're specifying its exact path (relative to your current directory).
Timothy P. Jackson
Valued Contributor

Re: question from a beginner..

All these commands are true if you are in the bourne shell. but if you are in the C shell you can do a

set path=($path /xxx/xxx)

to put the directory in the path.

Tim
Brian Kinney
Frequent Advisor

Re: question from a beginner..

UNIX utilizes a variable named PATH to tell the environment where to look for software to run. If you'd like to see what is in your PATH variable, type in:

echo $PATH

and you'll see something like:

/bin:/usr/sbin:/usr/ccs/bin:/usr/bin:

if "xxx" is not sitting in one of these directories it will never find "xxx" to run it.

The "./" means "search from this point."

You could modify your .profile to include your current location by default, simply by changing the PATH variable. For simplicity, put these two lines at the END of your .profile script:
PATH=$PATH:.
export PATH

WARNING! The system administrator account should never use the "dot" in their default path, as it would be a security risk. I personally take "." out of my login scripts to avoid this security flaw.

A better idea would be to organize all of your favorite tools into a specific directory, such as a "bin" directory placed inside your home directory:

cd (this sends you to your home directory)
mkdir bin
cp xxx ~/bin

vi .profile
PATH=$PATH:~/bin
export PATH

A final note: .profile is only read upon login OR when you specifically "source" it. After your edits, either logout and log back in, or use:

. .profile

to source the .profile all over again.

Spend a little time reading the man pages on sh and csh. The expressions of "., .., ~," and others are defined there. .profile is for sh, while .cshrc is for csh.

Good luck!
"Any sufficiently advanced technology can be indistinguishable from magic" Arthur C. Clarke. My corollary - "Any advanced technology can be crushed with a sufficently large enough rock."
Steven E. Protter
Exalted Contributor

Re: question from a beginner..

Yes,

its Steve your Jewish Grandmother reminding you about security.

Don't ever put . into the root path. I don't understand or remember why, but its a huge security problem.

Happy New Year, though mine started a few months ago.

Steve
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
Ian Dennison_1
Honored Contributor

Re: question from a beginner..

Steven

As an aside, I believe the reason for leaving out ./ from the PATH is for explicitness.

If (god forbid) you create a script in the local directory which also exists under the same name in another directory, and you run the command without the ./ prefix, the wrong script could be executed. By explicitly specifying current directory, you know exactly which script is running.

Share and Enjoy! Ian
Building a dumber user
Ravi_8
Honored Contributor

Re: question from a beginner..

HI,

#echo $PATH
if the program that you are executing is in the PATH directories then you can execute the program from wherever you are in that system, otherwise cd to that directory (where the program exist) and ./ will execute the program. if you add the program directory path to PATH it can be executed from anywhere in that machine.
never give up