Operating System - HP-UX
1833378 Members
3286 Online
110052 Solutions
New Discussion

Re: interesting unix problems

 
SOLVED
Go to solution
Sergey_27
Occasional Advisor

interesting unix problems

1. Can anyone suggest how to make ksh execute some scripts and stay interactive?

The idea was to open a new ksh with preset aliases and aliases exporting does not work.

2. Does any one have an example of aliases exporting?

Thanks.
11 REPLIES 11
Sridhar Bhaskarla
Honored Contributor

Re: interesting unix problems

Hi,

Check the following script.

$cat scr

. ./aliases.sh

printf "enter your name:"
read name
echo "This is from interaction - $name"
echo "Below is the alias doit"
doit

$cat aliases.sh
alias doit="echo this is doit"

$./scr
enter your name:test
This is from interaction - test
Below is the alias doit
this is doit

You can define alias in the original script itself if you want.

See if it helps you.

-Sri



You may be disappointed if you fail, but you are doomed if you don't try
john korterman
Honored Contributor

Re: interesting unix problems

Hi,

try this thread:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xe88093e260b0d611abdb0090277a778c,00.html

regards,
John K.
it would be nice if you always got a second chance
John Dvorchak
Honored Contributor

Re: interesting unix problems

I would think that one solution is to setup your environment variables in a file and then source them when you run the ksh command:

ie:

/tmp/your_file_with_vars:

alias new=vi
alias ll="ls -al"


Then just after you run the ksh command just source that file. To source a file enter the dot "." then a space then the path to the file:

root> . /tmp/your_file_with_vars

any environment vars setup in that file will stay in the shell until you exit the shell.
If it has wheels or a skirt, you can't afford it.
Sergey_27
Occasional Advisor

Re: interesting unix problems

Sri,
that was not aliases exporting.
You defined aliases in the same shell as script scr runs by sourcing aliases file.
Sridhar Bhaskarla
Honored Contributor

Re: interesting unix problems

Hi Sergei,

Look at the man page of ksh

//keywords listed above. Aliases can be created, listed, and exported
with the alias command and can be removed with the unalias command.
Exported aliases remain in effect for subshells but must be
reinitialized for separate invocations of the shell (see Invoking ksh
below).
//


If it is a seperate invocation of the shell, then, you will have to source in the aliases again which was what I did. There are few aliases compiled into ksh itself that are available to all the shells.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sergey_27
Occasional Advisor

Re: interesting unix problems

Sri,

Do you have an example that show that alias is effective for a sub-shell without re-initialization? To me if you have to define alias again it was not exported.

It looks like "alias -x" is useless.

John,

I can put aliases in the file no problem, but
how can I execute that file automatically and leave that shell running without going into trouble of installing expect?

Thanks for all your help

John Dvorchak
Honored Contributor

Re: interesting unix problems

Ok I think I know what you are asking for. You want to run a new shell and have it source your env parms with aliases etc. Then from the script that you run in the new shell place the line:

. /tmp/your_parm_file

on a line by itself in that script.

Maybe I am not understanding what specifically you want to do. Let me know.
If it has wheels or a skirt, you can't afford it.
Sridhar Bhaskarla
Honored Contributor

Re: interesting unix problems

Well I guess I understand what you are trying to do now.

See if this works.

ENV='${MyFILE[ (_$- = 1) + (_ = 0) - (_$- != _${-%%*i*}) ]}'
MYFILE=~/.kshrc
export ENV MYFILE

Put the above in your .profile and login again. Then the aliases in .kshrc should be available to all your subsequent subshells.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor
Solution

Re: interesting unix problems

Also Sergei,

Look at the following document for more hints

http://docs.hp.com/hpux/onlinedocs/B2355-90046/B2355-90046.html

Particularly the "Advanced Concepts" where it explains about ENV variable.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Leif Halvarsson_2
Honored Contributor

Re: interesting unix problems

Hi,

I have the following in my .profile

export ENV=$HOME/.kshrc

And the aliases is defined in .kshrc.
Sergey_27
Occasional Advisor

Re: interesting unix problems

Thanks everybody,

to summarize:

1. export ENV=filename and ksh will execute that file and stay interactive

2. export of aliases does not work but thats ok because ENV in #1 could be dynamic and all aliases could go there.

Thanks!!!