Solved

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

Posted on 2002-07-26
12
232 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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.

746 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

13 Experts available now in Live!

Get 1:1 Help Now