The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
change directory using shell script laxmi Shell Programming and Scripting 0 01-17-2008 07:12 AM
Change of directory thru script shiningram Shell Programming and Scripting 4 03-29-2007 04:30 AM
Change Directory via a script? George Borrmann Shell Programming and Scripting 3 10-09-2006 09:13 PM
Change Password In A Shell Script pintu_asim Shell Programming and Scripting 6 06-29-2006 11:16 AM
change user through shell script raviraushanjha UNIX for Dummies Questions & Answers 0 12-12-2005 03:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-17-2008
laxmi laxmi is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 19
Change directory in a shell script

How do u change ur directory using a shell script??
  #2 (permalink)  
Old 01-17-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is online now Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,988
same way as you do it without a shell script.
  #3 (permalink)  
Old 01-17-2008
laxmi laxmi is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 19
i tried giving the command 'cd /home/username' in my shell script and after executing the script i'm back in the directory where i started..
  #4 (permalink)  
Old 01-17-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is online now Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,988
cause you work in a subshell in your script. do something like this in your script:

#!/your/shell
cd /home/username
pwd
exit 0
  #5 (permalink)  
Old 01-17-2008
laxmi laxmi is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 19
I tried what u said.. But i'm still in the current directory and not in the one i specified in the shell script
  #6 (permalink)  
Old 01-17-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by laxmi View Post
I tried what u said.. But i'm still in the current directory and not in the one i specified in the shell script
You can change the directory. But it depends on what you are trying to achieve with your script.

Run your script as
Code:
. ./myscript.sh
When you run the script in this manner, all the changes you make to env variables will remain after your exit the script.
  #7 (permalink)  
Old 01-17-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is online now Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,988
and what is the output of "pwd" in the script?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0