1

I need to set a path for a variable $week4 to be Week4/assignment so that typing cd $week4 will change the working directory to Week4/assignment/

I've seen a few examples of similar stuff on here, but I haven't been able to make it work for me. Help is appreciated!

0

2 Answers 2

3

Since your path has spaces in it you need to enclose both the path AND the variable in "". Try this from the command line.

export week4="/home/Justin/Week 4/assignment/"

Now you should be able to navigate to that directory by typing cd $week4

If you want to make this permanent then add the same line to your .bashrc file.

0

To do that you can add following in your ~/.bashrc file .

  WEEK=/path/of/your/dir/

Open ~/.bashrc file using gedit ~/.bashrc and add above in it an save it.

Now you can use cd $WEEK to cd your folder

5
  • when I try to access my ~/.bashrc, I get a "permission denied" mesage. I tried typing WEEK4=mypath in my home directory home/Justin and it was accepted. However, when I went to type "cd $WEEK4" it got the message saying no such directory
    – Justin
    Sep 23, 2014 at 14:18
  • Have you changed the permission or owner of ~/.bashrc file?. And for the second part of your question, use WEEK=/home/Justin/Week4/assignment/ if /Week4/assignment/ directory is in your home folder.
    – g_p
    Sep 23, 2014 at 14:26
  • For the second part, I typed the full path which was "week4=Linux Programming 1/Week4/Assignments" and it was accepted. (Yes this is a homework assignment). Linux Programming 1 is a directory located in my home folder. When I went to then type "cd $week4" I got an error message saying no directory
    – Justin
    Sep 23, 2014 at 14:40
  • As your path contain space. Either remove space or use command in following ways. week4="Linux Programming 1/Week4/Assignments" and for cd cd "$week4"
    – g_p
    Sep 23, 2014 at 14:48
  • Hmmm, still didn't work. I must be doing something wrong
    – Justin
    Sep 23, 2014 at 15:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .