Click to See Complete Forum and Search --> : Alias command to go to a dir or subdirectory


lagdawg
09-05-2007, 09:46 AM
Hello,

I currently must access a Unix quite often and change to a certain directory.

I have aliased a command that takes me to that directory in my .cshrc. (This was set up by someone else and I just copied it for my use).


alias path1 'cd /patha/'
alias path2 'cd /pathb/'
alias goDir 'path1;path2;clear;ls'


As of recently this directory has become filled with alot of subdirectories and I would like to modify my alias command so that if I type "goDir" it takes me to the directory, but if I type "goDir subdir" it will take me directly to the sub directory.

I have tried:

alias goDir 'path1;path2;cd \!*;clear;ls'


That works if you specify a subdirectory but if you don't then it predictably just goes to your home folder.

Any help in solving this issue would be greatly appreciated. Thanks.

X_console
09-05-2007, 01:05 PM
You might try using the CDPATH environmental variable instead. Check the bash manual for further details. Assuming you have a directory /foo/bar:

export CDPATH=.:/foo

Now typing cd bar will take you directly to /foo/bar. Basically any subdirectory inside foo will be accessible.

lagdawg
09-10-2007, 09:47 AM
The system I am working on (HP-UX) does not have the export utility so I cannot use it. Is there another way to accomplish this without writing a seperate script?

bwkaz
09-10-2007, 06:32 PM
export isn't a separate program, it's a shell built-in. If you get an error when trying to export the variable all in one shot, try this instead:

CDPATH=.:/foo
export CDPATH If you still get an error, then you're not using a Bourne-compatible shell, you're probably using a C shell. This is a horrible idea IMO for several reasons (see e.g. "csh programming considered harmful" -- Google it), but foremost among them in your case is that I don't think csh supports $CDPATH. I'm not sure on that, however, so you can try to setenv CDPATH .:/foo and see if that makes it work.

hotcold
09-11-2007, 12:21 PM
Hi.

I agree partially with bwkaz: the csh family is not a good shell for scripting. I have found it acceptable for interactive use. The tcsh is said to support cdpath:
cdpath A list of directories in which cd should search for subdirecto-
ries if they aren't found in the current directory.

-- excerpt from man tcsh
cheers, hotcold