Change to a new working directory...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Change to a new working directory...
# 1  
Old 06-29-2005
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  
Old 06-29-2005
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  
Old 06-29-2005
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.
Smilie
# 4  
Old 06-29-2005
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  
Old 06-29-2005
MySQL

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.

Smilie
# 6  
Old 06-29-2005
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Change delimiter is not working using awk

I have file 2.txt and I want to change the delimiter form , to : Not sure what is the problem with below command cat 2.txt 1,a 2,b 3,d awk 'BEGIN {FS=",";OFS=":";} {print $0}' 2.txt Please use CODE tags as required by forum rules! (11 Replies)
Discussion started by: vamsi.valiveti
11 Replies

2. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

3. UNIX for Dummies Questions & Answers

How to change database directory to another directory?

Hi, I Installed mysql on my CentOS 6.2 Server. But when I tried to change the location of /var/lib/mysql to another directory. I can't start the mysql. Below is what I've done yum install mysql mysql-server mysql-devel mkdir /path/to/new/ cp -R /var/lib/mysql /path/to/new chown -R... (1 Reply)
Discussion started by: ganitolngyundre
1 Replies

4. Shell Programming and Scripting

FTP mget * not working after change directory -cd

Hi everyone, I have an Linux FTP script to get files from different AS400 mailboxes and store in different local directories. I had to use mget * option becuase there is no fixed destination file name means filename can change. The following FTP script is working fine if we have single file... (5 Replies)
Discussion started by: oravikiran
5 Replies

5. Linux

DST Time Change for positive timezones not working

I was doing timezone and DST testing which is required for some of my products Here is the strange behaviour i observed First i did set the timezone to PST 2010 (which is less than GMT basically negative timezone) zdump -v /etc/localtime |grep 2010 /etc/localtime Sun Mar 14 09:59:59... (0 Replies)
Discussion started by: ravindra1103
0 Replies

6. UNIX for Advanced & Expert Users

How do I change the minimum working frequency ?

The file /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_frequency reads a value of 800 Mhz . The powertop tool also suggested that 800 Mhz w3as the minimum frequency being used . I changed the above-mentioned file to 1.6 GHz and monitored powertop tool again . To my surprise, it still said that... (3 Replies)
Discussion started by: vishwamitra
3 Replies

7. UNIX for Dummies Questions & Answers

How to change current working directory for dbx on UNIX?

How to change current working directory for dbx on UNIX? means I'll run pgm from one directory , but getcwd() should return path which I want to be, which is not d current dir :) (5 Replies)
Discussion started by: login0001
5 Replies

8. Shell Programming and Scripting

how to change working directories in perl?

i am new to perl. i am writing a perl script. i want to know how to change the working directories? for ex. i have a perl script in c:\proj\ . i want to run this script in this directory but i need my script to change its working directory to D:\xyz\ dynamically in the script. your help is... (1 Reply)
Discussion started by: megastar
1 Replies

9. UNIX for Dummies Questions & Answers

Time change not working...

Hi, I am pretty new to the Solaris world. Just installed the version 8 and found that the time is off. I am in the Central time zone. In the beginning, the date and time was off by a day. After changing the /etc/default/init, there is no avail. The date is now correct but the time is still 5 hours... (7 Replies)
Discussion started by: conflansun
7 Replies
Login or Register to Ask a Question