Computing.Net > Forums > Linux > how to use 'cd' command in shell sc

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to use 'cd' command in shell sc

Reply to Message Icon

Name: Prashanth M.N.
Date: March 12, 2003 at 23:52:36 Pacific
OS: linux 7.1
CPU/Ram: p3, 128mb
Comment:

how to make the command 'cd' work in shell script to change directory?



Sponsored Link
Ads by Google

Response Number 1
Name: 3Dave
Date: March 13, 2003 at 01:27:03 Pacific
Reply:

What isn't working about it? You may find it helpful to enclose the path in quotes or use the \ escape character if you have any spaces in the name, eg:
#!/bin/bash
cd /home/foo/my\ folder


0

Response Number 2
Name: Don Arnett
Date: March 13, 2003 at 13:08:48 Pacific
Reply:

The 'cd' command works just as normal inside a shell script. The thing that is probably throwing you off is that when the script finishes, you are in the same directory as where you started. That is normal.

When you call a shell script, I believe that you are starting another shell, so using 'cd' in the new shell doesn't effect (affect??) the current directory in the calling shell.

To show yourself that it is changing directories, put these lines in a script and execute it:


echo $PWD
cd someNewDirectory
echo $PWD



0

Response Number 3
Name: prashanth
Date: March 14, 2003 at 18:48:14 Pacific
Reply:

try the docs is /usr/share


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: how to use 'cd' command in shell sc

How to use Wine program www.computing.net/answers/linux/how-to-use-wine-program/13911.html

How to use sed to remove ^M from files? www.computing.net/answers/linux/how-to-use-sed-to-remove-m-from-files/9335.html

How to use RPM under windows? www.computing.net/answers/linux/how-to-use-rpm-under-windows/18015.html