LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-31-2008, 12:52 AM   #1
JATA01
Member
 
Registered: Nov 2007
Posts: 207

Rep: Reputation: 15
Lightbulb 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
 
Old 01-31-2008, 02:48 AM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
When you use cd in a script the script will change back to the starting dir on exit - i.e. back where you began.
 
Old 01-31-2008, 03:19 AM   #3
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
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!
 
Old 01-31-2008, 03:29 AM   #4
JATA01
Member
 
Registered: Nov 2007
Posts: 207

Original Poster
Rep: Reputation: 15
It's working perfectly.

I have also tried:
$. ./testscript

Thanks All.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration