Operating System - HP-UX
1826498 Members
1930 Online
109692 Solutions
New Discussion

Re: Setting system variable

 
SOLVED
Go to solution
Scott Sabo
Frequent Advisor

Setting system variable

How do I set a system variable, called $PWD, to the current working directory.

It should stay defined.

This is needed to run an application.

Thanks for your help.
16 REPLIES 16
G. Vrijhoeven
Honored Contributor

Re: Setting system variable

Scott,

It is set default, as far as i know.

if not:

PWD=`pwd`

Regards,

Gideon
Mark Grant
Honored Contributor

Re: Setting system variable

THe above option will only change PS1 to the directory you happen to be in at the time. Try

export PS1="\$PWD "

Never preceed any demonstration with anything more predictive than "watch this"
Bharat Katkar
Honored Contributor

Re: Setting system variable

Hi,

This should work.

# export PATH=`pwd`

Check to see the change affected;
# echo $PATH

Regards,


You need to know a lot to actually know how little you know
KapilRaj
Honored Contributor

Re: Setting system variable

It is a defualt behaviour of any shell I believe ..

You need not set it manually

Kaps
Nothing is impossible
Mark Grant
Honored Contributor

Re: Setting system variable

Sorry!!!

Completely misread the question! The other answers here are correct.

However, $PWD is usually set by default
Never preceed any demonstration with anything more predictive than "watch this"
Bharat Katkar
Honored Contributor

Re: Setting system variable

Sooooooorry,
I got confused ... Ignore entirely my post.
You need to know a lot to actually know how little you know
Stuart Browne
Honored Contributor

Re: Setting system variable

'PWD' is an internally updated environment variable updated by the shell as you change directories.

Is there a particular reason you awnt it set to the current working directory?
One long-haired git at your service...
Jeroen Peereboom
Honored Contributor

Re: Setting system variable

L.S.

I agree with Stuart: it is set automatically and I see no need to change it manually.
Check your shell's manual page. I cannot find $PWD in the sh-bourne man page (which doesn't mean PWD is not set automatically) but is is described in the sh-posix and ksh man page:
PWD: the present working directory set by the cd command.

((I am not sure about the c shell (csh). I cannot find PWD in the csh manpage (?? can you check that??). If your users are using the cshell you may change it to the posix shell (ask them first if they login interactively because the shells differ a lot!) or use 'setenv PWD $cwd'. On my Linux system (no HP-UX available at this moment) csh sets my $PWD automatically.))

What is your problem with the application?
If you type echo $PWD before starting the application do you see the current working directory?

JP
Anupam Anshu_1
Valued Contributor

Re: Setting system variable

PWD is not a system variable but its a shell variable. When you change the directory, the value for PWD changes its self. You can verify the same by doing the following on the command prompt:

$ echo $PWD
/home/anshu
$ cd /tmp
$ echo $PWD
/tmp

So PWD will have the current directory information until unless its changed puposely.

More over, in your script you can always assign the value to PWD as follows:

PWD=`pwd`

HTH,

Anshu
Eric Antunes
Honored Contributor

Re: Setting system variable

As said before PWD is a system variable so you do not need to set it. Just use it!

I think you want to store the PWD value at a given time. If you want this do:

export PWD_NOW=`pwd`;

And you'll have it stored in PWD_NOW!
Each and every day is a good day to learn.
Scott Sabo
Frequent Advisor

Re: Setting system variable

Ok, it appears that the app is looking for the current directory (pwd) as set in a variable called PWD (uppercase), which is not set to anything.

Help me, Hp-wan-kenobi...


Trond Haugen
Honored Contributor
Solution

Re: Setting system variable

What shell are you running?
PWD is set in standard Posix shell. But if you are running some other shell that may not be the case.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
rmueller58
Valued Contributor

Re: Setting system variable

If you what $PWD=PS1 Global you need to place your variable definition in /etc/profile

it Requires exporting two variables

export PS1='$PWD'
export PWD=`pwd`

this should resolve your issue.

I generally place a "$" for not root users and "#" for root in the
export PS1='$PWD' # String

You can at this snippet into your profile to do that
export wai=`who am i|awk '{print $1}'`

if [ $wai = 'root' ]
then
export PS1='$PWD'"#"
export PWD=`pwd`
else
export PS1='$PWD'"$"
export PWD=`pwd`
fi


Hope it helps..
rmueller58
Valued Contributor

Re: Setting system variable

BTW

the snippet will work on most Un*x systems,

I've used it on Solaris, AIX, SCO, HP/UX, DG/UX, and Linux flavors. I've not tried "Cygwin" but my guess it'd work.

I noticed someone using PATH ??? don't forget your coffee before you write and test scripts, your wind up wandering what you did!

rmueller58
Valued Contributor

Re: Setting system variable

BTW $PWD is a variable and not general system defined it requires using the "pwd" command.

iminus
Frequent Advisor

Re: Setting system variable

If you are using ksh: export PWD=
If you are using csh: setenv PWD
hope it helps