Solved

Sub Shell

Posted on 2001-07-17
12
311 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 5

Expert Comment

by:marecs
Comment Utility
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
Comment Utility
you could put it in /etc/profile, but then everyone would get it.

Mike
0
 

Author Comment

by:sundarmv
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks marecs,

I am expecting more..
0
 

Author Comment

by:sundarmv
Comment Utility
Thanks marecs,

I am expecting more..
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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.

771 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

7 Experts available now in Live!

Get 1:1 Help Now