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
How to change current working directory for dbx on UNIX? login0001 UNIX for Dummies Questions & Answers 5 04-26-2007 07:47 AM
working directory shown swchee UNIX for Dummies Questions & Answers 3 05-11-2006 04:05 AM
how to change working directories in perl? megastar Shell Programming and Scripting 1 11-02-2005 03:05 PM
Getting present working directory winsonlee High Level Programming 0 08-07-2004 10:32 AM
Time change not working... conflansun UNIX for Dummies Questions & Answers 7 11-02-2001 01:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-28-2005
jagannatha jagannatha is offline
Registered User
  
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Change to a new working directory...

I need to CD to a particular directory to check log files and interface files. Instead of typing the path manually, is there a way of getting a script to change my working directory to the one I need?

Currently I have a script that CD's to the directories I need but a soon as the script exits, I am back in my home directory. I would like it to change and then exit leaving me in the desired directory.

Thanks for help offered
  #2 (permalink)  
Old 06-29-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Its all a matter on how you call the script.

Say I have /home/jag/jag.sh as

Code:
#!/bin/sh

cd /home/jag/temp
If you run the script as

sh jag.sh

or

./jag.sh

you will not move to ~/temp.

Run the script as

. ./jag.sh

Reason being, the first two ways of running the script would run in a subshell of the current shell. i.e after a fork and exec.

In case . ./jag.sh, you are running the script within the current shell.

Vino
  #3 (permalink)  
Old 06-29-2005
jagannatha jagannatha is offline
Registered User
  
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Hi vino,

Thanks heaps I tried your advise, but I keep getting -bash: ../stpth: No such file or directory.

it will only run when I use stpth without any path indications.

I am using Linux/bash.

I see what you mean about the seperate shell, not the original shell having the directory changed.

I will keep trying for an answer.
  #4 (permalink)  
Old 06-29-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,209
Quote:
Originally Posted by jagannatha
Hi vino,

Thanks heaps I tried your advise, but I keep getting -bash: ../stpth: No such
Look carefully at the previous posts there was a space between the two '.' in the post.
  #5 (permalink)  
Old 06-29-2005
jagannatha jagannatha is offline
Registered User
  
 

Join Date: Oct 2002
Location: Auckland, NZ
Posts: 49
Thumbs up

I need to get my glaesses checked thanks for the heads up!

And Yes it worked fine.

Excellent stuff, I knew I would get the right answer here.

  #6 (permalink)  
Old 06-29-2005
locustfurnace locustfurnace is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2004
Posts: 232
Though not a script, pushd works well for this, cuts down typing out a whole directory name a second time.

man pushd


http://linux.about.com/library/cmd/blcmdl1_pushd.htm
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 06:11 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