LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 04-28-2008, 02:33 PM   #1
darkside720
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

#!/bin/sh
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?

Thanks,
darkside
 
Old 04-28-2008, 02:36 PM   #2
pixellany
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, 02:56 PM   #3
darkside720
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, 03:45 PM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

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:
Code:
#!/bin/bash
cd /
exec bash
whether or not this will be of any use is another matter.

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

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


Reply


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 06:00 PM
Creating script to change ownership directory on RHEL4U3 at startup Ferianto Linux - Enterprise 9 02-13-2008 10:01 PM
Script to change directory gudum35 Linux - General 5 05-31-2006 03:43 PM
script to change directory trout21 Linux - Newbie 9 02-17-2004 12:49 PM
Help creating a directory back up shell script WarriorWarren Linux - General 6 04-06-2003 09:56 AM


All times are GMT -5. The time now is 10:53 PM.

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