The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
To call/execute a shell script from a shell script konark UNIX for Dummies Questions & Answers 1 10-26-2007 05:16 PM
How to pass a parameter from one Shell-script to another Shell-script subodhbansal Shell Programming and Scripting 2 09-22-2007 05:19 AM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 08:42 PM
Have a shell script call another shell script and exit heprox Shell Programming and Scripting 2 11-20-2006 08:17 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-14-2004
Spetnik Spetnik is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 34
cd in shell script

I have a shell script (bash shell) that just has a cd command, but when it runs, the directory does not change. How can I get this to work?
  #2 (permalink)  
Old 01-14-2004
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
It would help greatly if you can post all or part of it... hard to say till we can see it.

You may not be having the problem you think... Is the cd /dir saved as a variable?

Im guessing this is Linux since its bash...
  #3 (permalink)  
Old 01-14-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
A shell script is executed in a sub process. If you use a cd command, that sub-process will change directories. But when the script finishes, the parent process resumes. A sub process cannot affect its parent's current directory.
  #4 (permalink)  
Old 01-14-2004
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
i should have remembered that from watching my ignite command kick off from cron... It executes a sh to run the make_tape_recovery from my mkignite.sh script.

It is best to use the full path in shell scripts imho...
  #5 (permalink)  
Old 01-14-2004
Spetnik Spetnik is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 34
the shell script just has the following:

cd /home/spetnik


I remember back in school on sh shell with SCO Unix V that I was able to make a similar script. Surely, there must be a way, no?

-Aaron
  #6 (permalink)  
Old 01-14-2004
Kelam_Magnus's Avatar
Kelam_Magnus Kelam_Magnus is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
I think you can save the path to a variable and call it...

OR maybe add the PATH to $PATH for the dir in your script and call it that way
  #7 (permalink)  
Old 01-14-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
You would have to run your cd script in your current shell, not a sub-shell, so...

. /path/to/script

...i.e dot space scriptname
Closed Thread

Bookmarks

Tags
linux

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:05 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