Solved

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

Posted on 2002-07-26
12
242 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
non-interactive authentication of sftp command in AIX 5.3 15 189
Unix / Linux grid computing 5 149
Unix/bash: scripted arithmetic 13 96
UNIX SCP 5 70
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now