Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a code with fortran and I have several different output saved in different directory.

During the Do cycle I saved the temporary PATH of the output in a file.txt

Now I'm trying to plot the results runtime, but I need to enter the PATH of the output to use allways the same gnuplot script.

I want to if is possibile from terminal (shell) to enter into the PATH written in file.txt, that is read the PATH from my file.txt and enter in PATH with cd command.

I tried with cat but nothing happends!

Anyone can help me?

share|improve this question
up vote 1 down vote accepted

You have several ways to do this, but the idea is always the same. How to use the output of cat ? There are 2 possible syntax, with backquotes and with $(command). I'll use the second one which is preferred (see [BashFAQ 82])

You can do it in one line

cd "$(cat file.txt)"

Or in two steps

path=$(cat file.txt)
cd "$path"
share|improve this answer
Thank you so much! I have resolved with the first solution! – Andrea Serani Jul 23 '13 at 14:36
Don't forget to mark one answer with the green V so that your question is marked as solved – Benoît Legat Jul 23 '13 at 14:47
ok now I have the same problem with ipython – Andrea Serani Jul 24 '13 at 11:05
Is possible to do the same think in Ipython, because the shell answer with an error! – Andrea Serani Jul 24 '13 at 11:06
f = open('file.txt') path_to_output = # strip to remove the spaces and new lines at the end and the beginning os.chdir(path_to_output) – Benoît Legat Jul 24 '13 at 19:01

So, you want to cd into a directory written in a text file using the shell? If so, use the following:

cd $(cat /path/to/file.txt)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.