Logo 
Search:

Unix / Linux / Ubuntu Answers

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds
  on Nov 30 In Unix / Linux / Ubuntu Category.

  
Question Answered By: Adah Miller   on Nov 30

One thing you can do in a script or on the command line is to not use the cd
command to change directories, but use the pushd and popd commands to keep a
directory stack. You can even save environment variables that define directory
paths or even the current directory stack with the dirs -l command:
curdirstk=`dirs -l`

If you use cd in a script to change the directory from the current directory
from which the script is launched, after the script exits, the current directory
is the same as the one from which the script was launched - because the script
starts up a subprocess environment which has no choice in the matter but to
expire when done which cancels any directory changes and subprocess environment
thus leaving you back in the current directory from which the script was
launched.

Share: 

 

This Question has 6 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Changing directories in a script Or get search suggestion and latest updates.


Tagged: