Solved

Sub Shell

Posted on 2001-07-17
12
319 Views
Last Modified: 2013-12-06
Hi,

 I am using HP-UX 11.0. If we run any script, obviously it will create subshell and it will run. At the end of execution, it will return to parent shell.

my question is,
the temp.ksh script has following code.

cd /home/aaa/sweet
--

I am executing above script in
/home/aaa > temp.ksh
/home/aaa >
It doesn't get affect, but my aim is to change directory to /home/aaa/sweet

can anybody help?

thanks in advance.
0
Comment
Question by:sundarmv
[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
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 5

Accepted Solution

by:
marecs earned 20 total points
ID: 6289437
if your interactive shell is ksh as well then
. temp.ksh
will execute the commands in the current shell. There is no way you can have the cd in your script affect you interactive shell.

what you may also want to look at is alias
alias mycd='cd /home/aaa/sweet'
0
 

Author Comment

by:sundarmv
ID: 6289554
Thanks marecs,

  I need some more information.
  Whenever i login to system.I want to use the said alias without putting into .profile? Is there any way to achive this?

0
 
LVL 5

Expert Comment

by:marecs
ID: 6289875
You can put the alias command in something like
go.ksh
and then do . go.ksh

I don't think there is an automatic way of doing it except from .profile

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:interiot
ID: 6289882
You CAN get it to change directories, in a few circumstances.

     --------------------------
     # dir_chooser.ksh

     # decide what directory we want...
     chosen_dir=/home/aaa/sweet

     echo $chosen_dir
     --------------------------

Then, at the prompt, type

     cd `dir_chooser.ksh`

or define an alias that does that.  But aliases are verboten?

Can you describe more fully what you're trying to do?
0
 

Author Comment

by:sundarmv
ID: 6290278
Thanks marecs and interiot,
* i have created single line script say aa
and contents like
 print /home/aaa/sweet/

 $ cd $(aa)
it is working fine, but everytime i need to give $(aa) like and its boring. Have you got any other alternatives.
 

* We have got common .profile. I don't want touch that.
But i have created my own .myprofile in my home directory, i run the .myprofile adhoc basis.
like
$ . .myprofile
i have defined something here
like
alias sweet='cd /home/aaa/sweet'
alias sugar='cd /home/aaa/sugar'
..
exec ksh
...

But problem is,
the defined alias is not working.
errors like
ksh : sweet : not found.
0
 
LVL 3

Expert Comment

by:interiot
ID: 6290367
Typically the common profile is in /etc/profile, and each user has a personalized .profile in their home directory.  Unless the account is shared by several users, you should be able to modify that without problem.

.myprofile won't be automatically loaded unless told to do so by one of the ksh startup files (eg. ~/.profile).
0
 
LVL 5

Expert Comment

by:marecs
ID: 6292668
And aliases are not passed down to the exec ksh as exported environment variables are.

Go for .profile in your home directory as interiot suggested.
0
 
LVL 3

Expert Comment

by:mrn060900
ID: 6293414
you could put it in /etc/profile, but then everyone would get it.

Mike
0
 

Author Comment

by:sundarmv
ID: 6293689
Hi ya,

 Sorry for late reply.

We are using group login, more than 50 people accessing that ~/.profile. That's why i have created .myprofile at my personnel directory for some purpose. I'll run that adhoc basis.

If i put alias in .profile and it is working fine. Is there any other solution to achive this.

Sorry to giving too much head ache.


0
 

Author Comment

by:sundarmv
ID: 6293797
Hi ya,

 Sorry for late reply.

We are using group login, more than 50 people accessing that ~/.profile. That's why i have created .myprofile at my personnel directory for some purpose. I'll run that adhoc basis.

If i put alias in .profile and it is working fine. Is there any other solution to achive this.

Sorry to giving too much head ache.


0
 

Author Comment

by:sundarmv
ID: 6298966
Thanks marecs,

I am expecting more..
0
 

Author Comment

by:sundarmv
ID: 6298969
Thanks marecs,

I am expecting more..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
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…
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…
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…

756 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