1833776 Members
2130 Online
110063 Solutions
New Discussion

Where is PWD set?

 
Kelvin Lai
Occasional Contributor

Where is PWD set?

Just curious. Does anyone know where the environment variable PWD is set?
13 REPLIES 13
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

I am

It's in your environment as a shell variable. 'env' and 'set' show this variable.

echo $PWD

-Sri


You may be disappointed if you fail, but you are doomed if you don't try
Michael Tully
Honored Contributor

Re: Where is PWD set?

Hi,

$PWD is set in your standard shell. If you type $PWD it will show you your current directory, another way to see your current shell variables is to type 'env'. This will include $PWD

HTH
-Michael
Anyone for a Mutiny ?
Kelvin Lai
Occasional Contributor

Re: Where is PWD set?

I know it is an environment variable($PWD) & I can echo it through "echo $PWD" but my question is, "Where is it set?" is there a configuration file? Is there anyway I can create my own PWD variable that behaves exactly like $PWD but without using the PWD variable?
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

There is no configuration file the contains this information. It is one of the variables that is loaded into memory when the shell is spawned. I am afraid you may not be able to create your own environmental variable.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Kelvin Lai
Occasional Contributor

Re: Where is PWD set?

Dear Sri,
1. You can create your own environment var by exporting the variables with the export command.
2. You can add environments to the shell by entering them in the ~/.profile file;)

My problem is creating my own PWD that acts as the environment var PWD. If you notice when you change a directory the environment var PWD changes as well. If you were to create MYPWD=$(pwd), when you change the directory it doesn't update.
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

Kevin,

You can create any number of variables. I was talking exactly what you said. Only $PWD will change when you change the directory. You cannot create your own variable that behaves like this. There are a set of variables that are fixed. Like PWD, DISPLAY, TMOUT etc., So you can't really create a variable that can function like DISPLAY variable.

I want to rephrase my last message -

I am afraid, you may not be able to create your own environment variable like PWD.

Hope I am little bit clear now :-)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

Kevin,

You can create any number of variables. I was talking exactly what you said. Only $PWD will change when you change the directory. You cannot create your own variable that behaves like this. There are a set of variables that are fixed. Like PWD, DISPLAY, TMOUT etc., So you can't really create a variable that can function like DISPLAY variable.

I want to rephrase my last message -

I am afraid, you may not be able to create your own environment variable like PWD.

Hope I am little bit clear now :-)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

Kevin,

You can create any number of variables. I was talking exactly what you said. Only $PWD will change when you change the directory. You cannot create your own variable that behaves like this. There are a set of variables that are fixed. Like PWD, DISPLAY, TMOUT etc., So you can't really create a variable that can function like DISPLAY variable.

I want to rephrase my last message -

I am afraid, you may not be able to create your own environment variable like PWD.

Hope I am little bit clear now :-)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

Kevin,

You can create any number of variables. I was talking exactly what you said. Only $PWD will change when you change the directory. You cannot create your own variable that behaves like this. There are a set of variables that are fixed. Like PWD, DISPLAY, TMOUT etc., So you can't really create a variable that can function like DISPLAY variable.

I want to rephrase my last message -

I am afraid, you may not be able to create your own environment variable like PWD.

Hope I am little bit clear now :-)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

Kevin,

You can create any number of variables. I was talking exactly what you said. Only $PWD will change when you change the directory. You cannot create your own variable that behaves like this. There are a set of variables that are fixed. Like PWD, DISPLAY, TMOUT etc., So you can't really create a variable that can function like DISPLAY variable.

I want to rephrase my last message -

I am afraid, you may not be able to create your own environment variable like PWD.

Hope I am little bit clear now :-)

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Michael Tully
Honored Contributor

Re: Where is PWD set?

Hi,

Have a look at the man pages for
sh-posix
ksh
sh

There is sufficient information there that should explain your question. Open the man pages and search for PWD.

-Michael
Anyone for a Mutiny ?
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

Due apologies. When I submit my reply, it was hanging, So, I kept on hitting submit so the mess.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: Where is PWD set?

Due apologies. When I submitted my reply, it was hanging, So, I kept on hitting submit so the mess.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try