?
Solved

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

Posted on 2002-07-26
12
Medium Priority
?
275 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 51

Accepted Solution

by:
ahoffmann earned 300 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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