Operating System - HP-UX
1837900 Members
3212 Online
110123 Solutions
New Discussion

add current directory (.) to the path

 
SOLVED
Go to solution
Reggie Chang
Frequent Advisor

add current directory (.) to the path

Hello,

I tried to add . (current directory) to the path (root account) on a hp workstation that is only connected to interior network, but there was no success.

The files that I modified are /.profile,
/etc/profile and /etc/PATH. What is the
right way to do it?

Best regards,

Reggie
7 REPLIES 7
Hasell Blad
Advisor
Solution

Re: add current directory (.) to the path

Hello,

Adding PATH /.profile applies
to your own shell.
But Adding PATH /etc/profile
applies to system wide shell.

PATH=$PATH:.


I tried to add . (current directory) to the path (root account) on a hp workstation that is only connected to interior network, but there was no success.

The files that I modified are /.profile,
/etc/profile and /etc/PATH. What is the
right way to do it?

Best regards,

Reggie
Hudson
Steven Sim Kok Leong
Honored Contributor

Re: add current directory (.) to the path

Hi,

In your root's .profile, specify

export PATH=$PATH:.

Note that for security concerns, adding the current directory to PATH is usually not recommended. If it is really necessary, add it right at the end of your PATH so that system directories take precedence over the current directory.

Hope this helps. Regards.

Steven Sim Kok Leong
Sanjay_6
Honored Contributor

Re: add current directory (.) to the path

Hi Reggie,

Add this line to your .profile,

export PATH=$PATH:.

This will allow the current directory to be search last. If you want the current directory to be searched first, do this,

export PATH=.:$PATH

Hope this helps.

Regds
Wodisch
Honored Contributor

Re: add current directory (.) to the path

Hello,

the *right* way is NOT to do this!
Add all the directories containing codefiles you need into "/etc/PATH" (must be a SINGLE line of text), and "~root/.profile", but never-ever the working directory!!!

Reason?
Just imagine somebody calling for your help with a file in "/tmp" - that happens, right?
Now that user had prepared some executables in "/tmp", like "mroe", "dir", "l", "cd.." or such - and as soon as you make that kind of typing mistake you are executing the attackers code :-(

Beware of that!
Wodisc
Bill Hassell
Honored Contributor

Re: add current directory (.) to the path

The problem is that you are running a workstation, probably using CDE which doesn't follow any 'normal' Unix rules about login, such as executing /etc/profile and .profile. This is standard (but bizarre) behavior. Read the comments in .dtprofile for some of the details. If you telnet into the workstation, /etc/profile and .profile will be run OK. Changing the last line to:

DTSOURCEPROFILE=true

will help but it still isn't a 'normal' Unix login.

So for starting terminal windows like dttrem or hpterm or even xterm using the CDE desktop, and you want normal Unix behavior, create an .Xdefaults file with something like this:

*loginShell: true
HPterm*background: navy
HPterm*foreground: white
Xterm*background: darkslateblue
Xterm*foreground: white

The *loginShell will cause the terminal emulators to 'really' login and use /etc/profile and .profile. You can change the default colors (and dozens of other decoration config and setting) in .Xdefaults. See the man page for each terminal emulator.

ANd after all that, the previous comments about adding . to your $PATH are quite valid. Someday, you'll cd into an unsafe directory, type an important command like su and giveaway your password to a hacker (do you know where your su came from?). So to execute a command or script in the current directory, you type two (only 2) extra leading characters: ./


Bill Hassell, sysadmin
harry d brown jr
Honored Contributor

Re: add current directory (.) to the path

Reggie,

Bill Hassell hit it right on the head, follow his suggestions IF you want to continue, BECAUSE Wodisch makes a great case against NOT adding the current directory to your path list! And I totally agree with Wodisch. if it's because someone is TOO LAZY to type in "./" before a command in their current directory, then I say screw them! Besides it's ridiculous and a security violation to allow any user access to any shell!

live free or die
harry


Live Free or Die
Steven Sim Kok Leong
Honored Contributor

Re: add current directory (.) to the path

Hi,

With regards to disallowing users in running any shell, you can make use of restricted sam to create a menu-like system:

# sam -r

In your /etc/profile, have statements that says:
========================================
trap "" 1 2 3

# your statement here

if [ "$LOGNAME" != "root" ]
then
/usr/sbin/sam -r
logout
fi

trap 1 2 3
========================================

Hope this helps. Regards.

Steven Sim Kok Leong