Link to home
Start Free TrialLog in
Avatar of abhishek_p
abhishek_p

asked on

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

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.
Avatar of bira
bira



 cd /root/animesh/private
  echo 'Where am I'
  pwd
If you want the directory in the same like:

cd /root/animesh/private
 echo "Where am I:" `pwd`
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
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abhishek_p

ASKER

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,
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
abhishek_p, perfect description of what happens ;-)

See my suggestion again, you need to source your script, or use an alias
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.
It's prompt and good response.
what do you mean by "funda" ?
Oh... "funda" means "fundamental stuff".... basically I was looking for, how this works?
hope you got the funda about . and source ...