This is probably a FAQ item but despite searching extensively with google I am unable to find an answerer to this question. Perhaps I am using the wrong words. In any case, at the risk of inducing some mirth at my ignorance, how can one script a cd command so that that the user remains in that directory when the script exits? I have to work with a long path to a project working directory and I would like to have a simple script called "current" which would produce the same effect as issuing this from the shell: cd ./very/long/path/to/obscurely/titled/project/directory I cannot seem to find anything that directly addresses this, other than to point out that shell scripts run in their own copy of the shell interpreter and so anything done to the PWD therein is local to the duration of the script. I could create a logical link from my home directory I suppose, but I desire a scripted solution. I really do not wish to program a utility to do this and I cannot believe that many people have not already addressed this desire with a straight forward answer. So if any of you have a simple to implement solution then could you share your answer with me? As I am a digest subscriber in addition to your answer to the list the favour of a direct reply is requested Sincerely, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3
James B. Byrne wrote:> This is probably a FAQ item but despite searching extensively with google > I am unable to find an answerer to this question. Perhaps I am using the > wrong words. In any case, at the risk of inducing some mirth at my > ignorance, how can one script a cd command so that that the user remains > in that directory when the script exits? > > I have to work with a long path to a project working directory and I would > like to have a simple script called "current" which would produce the same > effect as issuing this from the shell: > > cd ./very/long/path/to/obscurely/titled/project/directory > > I cannot seem to find anything that directly addresses this, other than to > point out that shell scripts run in their own copy of the shell > interpreter and so anything done to the PWD therein is local to the > duration of the script. I could create a logical link from my home > directory I suppose, but I desire a scripted solution. > > I really do not wish to program a utility to do this and I cannot believe > that many people have not already addressed this desire with a straight > forward answer. So if any of you have a simple to implement solution then > could you share your answer with me? > > As I am a digest subscriber in addition to your answer to the list the > favour of a direct reply is requested >In this case the use of an alias is probably what you want ... alias current='cd /path' You can then type current at the command prompt can go there. You can put that command in your .bashrc with your other aliases as well to make it persistent across reboots. Thanks, Johnny Hughes -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: <http://lists.centos.org/pipermail/centos/attachments/20070730/1169c29a/attachment.sig>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 James B. Byrne wrote:> This is probably a FAQ item but despite searching extensively with google > I am unable to find an answerer to this question. Perhaps I am using the > wrong words. In any case, at the risk of inducing some mirth at my > ignorance, how can one script a cd command so that that the user remains > in that directory when the script exits? >pushd newdir # at the beginning of the script popd # before exiting Alternately: curdir=$(pwd) # at the beginning of the script cd $curdir # before exiting For further information (and to find a list of the really useful features of the BASH shell) do: man bash Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (GNU/Linux) iD8DBQFGrhn3CFu3bIiwtTARAmv6AJ4kb6VG4HSyj/aChZgzJ9M64PW8SwCfYHV6 kJhMc6RYuZVW7JXSpYOPczg=I0qY -----END PGP SIGNATURE-----
On Mon, July 30, 2007 13:02, Johnny Hughes wrote:> > In this case the use of an alias is probably what you want ... > > alias current='cd /path' > > You can then type current at the command prompt can go there. > > You can put that command in your .bashrc with your other aliases as well > to make it persistent across reboots. > > Thanks, > Johnny Hughes >and On Mon, July 30, 2007 13:06, Brent L. Bates wrote:> Instead of a script, how about a shell alias? In the csh shell, I'd > do > something like the following: > > alias cd_project "cd ./very/long/path/to/whatever"Thank you both ever so much. I would never have though of using an alias but that seems the sensible solution. Sincerely, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3
On Mon, 2007-07-30 at 12:49 -0400, James B. Byrne wrote:> <snip>> I have to work with a long path to a project working directory and I would > like to have a simple script called "current" which would produce the same > effect as issuing this from the shell: > > cd ./very/long/path/to/obscurely/titled/project/directory > > I cannot seem to find anything that directly addresses this, other than to > point out that shell scripts run in their own copy of the shell > interpreter and so anything done to the PWD therein is local to the > duration of the script. I could create a logical link from my home > directory I suppose, but I desire a scripted solution. > > I really do not wish to program a utility to do this and I cannot believe > that many people have not already addressed this desire with a straight > forward answer. So if any of you have a simple to implement solution then > could you share your answer with me? > > As I am a digest subscriber in addition to your answer to the list the > favour of a direct reply is requested > > Sincerely, >In addition to the other suggestions, I would like to add a simple user- invoked solution. "Source" or ".". Any script invoked in this manner runs in the current instance of the shell. IMO, if the user(s) are somewhat competent ("obscure project directory" leads me to believe this may be the case), this simple solution may be the most "elegant".