Solved

Sub Shell

Posted on 2001-07-17
12
317 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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.

770 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