Computing.Net > Forums > Unix > Novice - change dir in shell script

Novice - change dir in shell script

Reply to Message Icon

Original Message
Name: Kevin Kelly
Date: March 25, 2003 at 09:18:00 Pacific
Subject: Novice - change dir in shell script
OS: Solaris
CPU/Ram: a lot
Comment:

I have a simple script that changes directory-
cd /newdirectory
pwd
- when I run this it seems to execute correctly, but after it executes I'm still in my original directory. I guess I'm changing directories in a different shell. Is there a way to change directories in my current shell?



Report Offensive Message For Removal


Response Number 1
Name: WilliamRobertson
Date: March 25, 2003 at 09:51:49 Pacific
Reply: (edit)

> I guess I'm changing directories in a different shell

Yes, a script always runs in a subprocess, so any cd or environment variable settings are lost when it exits.

You can either use ". scriptname" i.e. [dot] [space] [scriptname], which will run it in the current process, or else define a function (functions also run in the current process).


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Novice - change dir in shell script

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge