LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell script (https://www.linuxquestions.org/questions/programming-9/shell-script-617571/)

JATA01 01-31-2008 12:52 AM

Shell script
 
Hi Friends,

I have a query about shell script.
Simply when we write a simple script like:-

cd /E*Fare/dist/src;pwd

and executing the script from ~/aksutils location we can find in /E*Fare/dist/src location but pwd output still shows the location ~/aksutils.

Thanks-
Shankar

dive 01-31-2008 02:48 AM

When you use cd in a script the script will change back to the starting dir on exit - i.e. back where you began.

blackhole54 01-31-2008 03:19 AM

If you wish the script to be able to change the working directory in you current shell, you must source the script instead of running it as a command. For example:

Code:

$ pwd
/home/user
$ echo "cd ~/misc" > testscript
$ . testscript
$ pwd
/home/user/misc

The dot followed by a space is what tells your shell to source the script. Everything in that script will then execute in your current shell ... so be careful what you do!

JATA01 01-31-2008 03:29 AM

It's working perfectly.

I have also tried:
$. ./testscript

Thanks All.


All times are GMT -5. The time now is 08:23 PM.