Operating System - HP-UX
1832974 Members
2546 Online
110048 Solutions
New Discussion

Re: how to add more alias to ksh

 
SOLVED
Go to solution
Shu Lei
Occasional Advisor

how to add more alias to ksh

After a user logged in, he run /usr/bin/ksh.
He only gets those complied alias as command "alias" shows. Is that possible to set more alias before the user runs "ksh" and take effect afterwards?

Note: the settings in $HOME/.profile or /etc/profile doesn't work, for it is a problem after login-shell is executed.

Thanks in advance.
Lorne
Lorne Shu
10 REPLIES 10
Roger Baptiste
Honored Contributor

Re: how to add more alias to ksh

Shu,

You can set additional aliases through alias command.
For eg: at command prompt:
alias X="ls"
alias Y="who"

Next time, you type X it
will run ls command ;
and Y will run who command.

You can include this alias
settings in your .profile
file, such that they are
set already when you login
to the account.

To display your aliases,
run alias command.

HTH
raj


Take it easy.
James R. Ferguson
Acclaimed Contributor

Re: how to add more alias to ksh

Hi:

You could source (read) a file containing alias commands after the login. Would that help?

#!/usr/bin/ksh
alias show=/usr/bin/echo

Assuming the above file was named $HOME/alias, then after logging in, do:

# . ./alias

Regards!

...JRF...
Craig Rants
Honored Contributor

Re: how to add more alias to ksh

Why does the user have to run ksh? If that is shell the user uses, then change that to their default shell. Also, the $HOME/.profile should work if the user is using ksh or sh, if they are using csh modify the .csh file with the alias settings.

Hope this answers your question.
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Shu Lei
Occasional Advisor

Re: how to add more alias to ksh

First of all, thanks for your time reading; however I think I have to make this problem more clear to all of you.

To use ksh is an option in a menu to normal users after they logged in, who are not supposed to have any knowledge of unix. Therefore I have to set everything before they use that.

The point is that I cannot find a way to set alias to ksh before users run it or to let it read a file containing alias settings when it is called.

Thanks again.
Lorne
Lorne Shu
Sridhar Bhaskarla
Honored Contributor

Re: how to add more alias to ksh

Shui,

Then you need to set it in your /etc/profile file.

I think adding this should work. Even you can keep your if statements only for a list of users.

if [ $SHELL = "/usr/bin/ksh" ]
then
alias elles="ls"
alias hoo="who"
fi

So this is applicable to all users that have /usr/bin/ksh as their shell.

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

Re: how to add more alias to ksh

Lorne,

I understood your problem. My above will not work. Please ignore it.

It may not be possible to do it because when you run /usr/bin/ksh, it is going to spawn a seperate shell that will not have information about the previous aliases. Whatever the aliases we get through alias command are precompiled into the shell.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Eugen Cocalea
Respected Contributor

Re: how to add more alias to ksh

Hi,

Use exec() to call ksh. In the man page of ksh, it says that you can make ksh to read the /etc/profile and the ${HOME:-.}/.profile, if the first character of arg0 of exec is -.

E.
To Live Is To Learn
Shu Lei
Occasional Advisor

Re: how to add more alias to ksh

Hi Eugen Cocalea,

Your idea sounds great, however I am not able to implement that. Have you tried it out?
I have tried some ways but still no idea about where to put "-" between "exec" and "ksh".

Sincerely, thanks to all the HP-UX experts who have given me ideas and helped me there.

Lorne Shu
Lorne Shu
Wodisch
Honored Contributor
Solution

Re: how to add more alias to ksh

Hello Lorne,

export ENV before the shell is started and point it to a shell-script containing the wanted alias commands.

Like:

export ENV=/usr/lbin/ksh-aliases
...
ksh

And in "/usr/lbin/ksh-aliases" you would have all your "alias this=that" statements...

HTH,
Wodisch
Shu Lei
Occasional Advisor

Re: how to add more alias to ksh

Hi Wodisch,

Thank you very much for the help! That's exact
the right answer. I wish I could help others just like what you did to me:)

Have a good day.
Lorne Shu
Lorne Shu