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,
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
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,
-----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
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".
William L. Maltby wrote:
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".
I'd go for the symlink in that case. Perhaps even a directory symlinked into everyone's home/Desktop directory that contains symlinks to the obscure places. This has the advantage of providing non-obscure visible names, working with GUI tools and is self-documenting with 'ls -l'.
On Tue, 2007-07-31 at 17:29 -0500, Les Mikesell wrote:
William L. Maltby wrote:
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
<snip>
As I am a digest subscriber in addition to your answer to the list the favour of a direct reply is requested
I tried, you bounced me for the return address. Sorry 'bout that!
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".
I'd go for the symlink in that case. Perhaps even a directory symlinked into everyone's home/Desktop directory that contains symlinks to the obscure places. This has the advantage of providing non-obscure visible names, working with GUI tools and is self-documenting with 'ls -l'.
I like that even more than the ".". The advantages you state sway me and require no expected level of "competency".
-- Bill