//View Tip #201
Similar Tips
» Find and replace with backup
» Splitting arguments with read
» Command line currency conversion
» swap files
» Fix the previous command

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Put the following alias in your profile to store a directory name to use later on:
alias sd='set \!:1=$cwd'


Example usage:
$ sd mydir
...
$ cd mydir


This method works for csh but not bash. For bash try the following function in your profile:
sd(){ export $1=$PWD; }


Then:
$ sd abc
...
$ cd $abc


View Comments »



Comments 

Add your comment

CAPTCHA

No HTML allowed. URLs will be linked with nofollow attribute. Whitespace is preserved.

AdrianTM
How about pushd and popd? Those who don't know UNIX commands are condemned to re-invent them.
Posted 2008-12-28 03:26:28
Barton
A nice compliment to this is

set | grep '^[a-z]'

Since bash variables and the body of all shell functions do not start with lower-case letters, this leaves a manageable list to look through, to remember which variables you set. If you start them all with 'a', they'll sort to the top.

AdrianTM: yes, pushd and popd have their place, as does 'cd -'. I find pushd and popd rather cumbersome, perhaps that's just because I don't know them very well. This tip is very light weight; I will definitely be adding it to my .profile.
Posted 2009-08-14 23:24:33

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit