8

For example there is a long path that I cd to very often. How do I store the path in a variable so that I can use it everytime?

For example: I wan to be able to do this

cd $path

instead of

cd /a/b/c/d/e/f 

everytime.

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
Lazer
  • 18,407

6 Answers6

10

In Bash shell:

export FOO="/a/b/c"

And you don't want to use $path. That's a special variable.

Paul Nathan
  • 1,816
7

It's not likely that you need your variable in the environment.

So, in csh instead of setenv, you can do:

set dir="/a/b/c/d/e/f"
cd $dir

or in Bash, instead of export:

dir="/a/b/c/d/e/f"
cd $dir
6

assuming you really want csh/tcsh syntax (as you have tagged your question), put this

setenv P1 "/a/b/c/d/e/f"

to your .tcshrc

after that you are able to do

cd $P1
akira
  • 63,447
4

Use export.

export your_path="/a/b/c/d/e/f"

cd $your_path

If you want it to persist through logins, you're going to need to edit it into your .profile file.

Satanicpuppy
  • 7,205
0

For csh you probably want to use cdpath . For bash, use CDPATH instead.

For example (bash):

prompt$ export CDPATH=:/a/b/c/d/e

prompt$ cd f
cd /a/b/c/d/e/f

You can also add more colon delimited directory targets. Keep the leading colon so CDPATH checks your current working directory first!

kmarsh
  • 4,998
0

If you just want to use the path for one session, set the variable as usual

set long="/some/long/path/to/a/directory"

You can then cd "$long" as often as you like until the shell terminates or you set long again.

If you're interested in the variable being available to processes run from the shell session you should set it in your environment

setenv long "/some/long/path/to/a/directory"

If what you want is for the variable to be available to every session, instead of just the current one, you will need to set it in your shell run control.

$EDITOR ~/.cshrc

Then add the set line or the setenv line shown above to automatically set the variable or environment variable for every session of csh.

phogg
  • 1,107