Solved

Shell .... what is it......

Posted on 2002-07-26
12
268 Views
Last Modified: 2010-04-21
Hi there,
   I wanted to execute a set of commands. I created a .sh file and wrote down all of them in that file. It contained the first two commands as

cd /root/animesh/private
echo 'Where am I'

So upon execution, it just printed "Where am I". I was expecting it to change the directory to the specified there. But it didn't happen so.

Can anybody tell me how to get that?
Regards,
Animesh.
0
Comment
Question by:abhishek_p
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 6

Expert Comment

by:bira
ID: 7181084


 cd /root/animesh/private
  echo 'Where am I'
  pwd
0
 
LVL 6

Expert Comment

by:bira
ID: 7181092
If you want the directory in the same like:

cd /root/animesh/private
 echo "Where am I:" `pwd`
0
 
LVL 6

Expert Comment

by:bira
ID: 7181113
That will show if cd command worked.
 you can also place a  set -x at the top of the script
 in order to debug it.

   set -x
   cd /root/animesh/private
   echo 'Where am I'
   pwd
   < other commands >
   # script end
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 7181129
> But it didn't happen so.
How did you proofe that?
It happend, see bira's suggestions.

Probably you expect that your shell, where you called your script, changes directory. That depends on how you called your script. It must be done like:
  . your-script.sh      # in ash, bash, ksh, pdksh, sh, zsh
  source your-script.sh # in csh, tcsh
0
 

Author Comment

by:abhishek_p
ID: 7183335
Yeah, that's fine... But probably I goofed up a bit. What I wanted is, to changes my present working directory to what I've given in this shell script for my present session.
   While executing the script, correct me if I'm wrong, it creates a child shell where it does all the processing mentioned in the script and then when it's over, it returns back to parent session. So the changes in the child session is not reflected in the parent shell which is what I'm trying to get...
regards,
0
 
LVL 4

Expert Comment

by:Monchanger
ID: 7183443
As far as I understand, you are correct and a child shell cannot affect the system variables of the parent. I found an explanation which explains what you might want to do:
http://www.faqs.org/faqs/unix-faq/faq/part2/ (section 2.8)

Hope this helps,
Monchanger
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7183756
abhishek_p, perfect description of what happens ;-)

See my suggestion again, you need to source your script, or use an alias
0
 

Author Comment

by:abhishek_p
ID: 7193929
Thanks for the compliment,if it is.. ;-), ahoffmann. Your trick worked. I'm sorry that I didn't give a try to other one. Actually it's Bash for me but only 'source sh.sh' works, not the other one.
   Anyway thanks again. But if you could explain me what is the funda here, then it'll be of much help. My mail id is alone18@rediffmail.com. Otherwise this place is also very fine and calm..... :-( .
Regards,
Animesh.
0
 

Author Comment

by:abhishek_p
ID: 7193936
It's prompt and good response.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7194557
what do you mean by "funda" ?
0
 

Author Comment

by:abhishek_p
ID: 7196692
Oh... "funda" means "fundamental stuff".... basically I was looking for, how this works?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7197170
hope you got the funda about . and source ...
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question