Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-28-2008, 03:33 PM   #1
LQ Newbie
Registered: Feb 2008
Posts: 11

Rep: Reputation: 0
Creating a script to change directory

Hey guys, kinda a newbie, but I created a script to change my directory to something like /var/log, but when I run the script it leaves me in the same directory. This is my script

cd mpw/chip/blk/hub/syn/run/g1t

so when I run the script, it does not bring me to that directory. however, I tried it by being root and it works. Is there any reason on why I am not able to run the script as a user?

Old 04-28-2008, 03:36 PM   #2
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
First, you have a relative path. The cd command won't work unless you are in the directory containing "mpw".

The other thing to check is the permissions.

When building up a script, first check the commands individually to be sure they do what you expect.
Old 04-28-2008, 03:56 PM   #3
LQ Newbie
Registered: Feb 2008
Posts: 11

Original Poster
Rep: Reputation: 0
Sorry for the mis-information. I am working within the path containing the mpw. As for the permissions, I and the owner of all dir and sub-dirs. just kills me that this won't work... I also added it to my .cshrc for the alias ' cd mpw/chip/blk/hub/syn/run/g1t ' and that didn't work as well.
Old 04-28-2008, 04:45 PM   #4
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

When you run the script, you create a subshell. When that subshell exits, you're left in your original shell, at the same place in the filesystem.
You'll have to replace the current shell with a new shell at the new location:
cd /
exec bash
whether or not this will be of any use is another matter.

Old 04-28-2008, 05:11 PM   #5
LQ Newbie
Registered: Feb 2008
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks guys, that worked.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
change a directory using script viveksnv Programming 5 02-20-2008 07:00 PM
Creating script to change ownership directory on RHEL4U3 at startup Ferianto Linux - Enterprise 9 02-13-2008 11:01 PM
Script to change directory gudum35 Linux - General 5 05-31-2006 04:43 PM
script to change directory trout21 Linux - Newbie 9 02-17-2004 01:49 PM
Help creating a directory back up shell script WarriorWarren Linux - General 6 04-06-2003 10:56 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:32 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration