How is the "Current Working Directory Maintined"
Hi
I was wondering how the current working directory is maintained in linux. I assumed it would simply be an environment variable, but all attempts i've made to change directory by resetting variables shown by env have failed. Is this something that is maintained internally in the command prompt (bash in my case)? The background to this is I'm setting up a script to remotely run commands over ssh. Since separate commands will unfortunately require separate SSH connections, I need to maintain (save and reload) items such as environment variables and current working directory from one call of the script to the next. Thanks for reading |
The current working directory is an attribute of each process and can be changed by the program in the process using the chdir(2) system call. The shell command cd makes the shell call chdir(2) and then set the $PWD special variable accordingly. The shell's command prompt string is often set to display the current working directory by the "special character" \w as documented here.
|
pwd will tell you your current directory, as will echo $PWD on my system
To change to another directory, use cd /path/to/dir $PWD will be updated to the new directory You can save these paths in an environment variable, and re-use them later. Try this: Code:
pwd Code:
pwd |
Thanks. Thats the information I was looking for...
It does however raise one concern. What other "attributes" do i need to be aware of? I'm trying to run a process a remote machine to mimic running on the local machine. I've covered:
Off the top of your head, is there any other attribute that I may need to copy across in order to get one system to mimic another? |
Depends on what you're trying to do. A couple of things that may be germane would be user & group ownership of the process, and the type of TTY to which the process is attached (if any). http://tldp.org/HOWTO/Secure-Program...processes.html should give you some decent background.
--- rod. |
All times are GMT -5. The time now is 07:16 AM. |