Solved

Sub Shell

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

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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 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.:
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.

910 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

20 Experts available now in Live!

Get 1:1 Help Now