Solved

Sub Shell

Posted on 2001-07-17
12
321 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

Independent Software Vendors: 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

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…
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 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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

724 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