Solved

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

Posted on 2002-07-26
12
248 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

803 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