Operating System - HP-UX
1827427 Members
3909 Online
109965 Solutions
New Discussion

Re: How to add alias in .profile

 
Sanjeev gupta_2
Frequent Advisor

How to add alias in .profile

Hi
I want to create a alias and put it in .profile. When I alias at command prompt , it works fine , but could not work with .profiel.
Pl. guide me how can i put alias in .profile to taht i can use it.

Thx
sanjeev
22 REPLIES 22
Pete Randall
Outstanding Contributor

Re: How to add alias in .profile

An alias is more commonly set up in your rc file. The rc file you use depends on your shell - ksh, for example would use the .kshrc file.


Pete

Pete
Senthil Kumar .A_1
Honored Contributor

Re: How to add alias in .profile

Hi Sanjeev,

First you need to include the following line in your .profile file.

ENV=$HOME/.kshrc
export ENV

After doing so, edit a file ".kshrc" in your home directory and include your alias lines in the file .kshrc as follows..

alias ll='ls -l'
alias lla='ls -la'
alias ltr='ls -ltr'
alias llh='ls -l . | egrep htm\|html'

After, you do so, log out your current session, and relogin.

Regards,
Senthil Kumar .A
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Sanjeev gupta_2
Frequent Advisor

Re: How to add alias in .profile

Hi,
It dosen't work.Pl. someone provide solution.
Mark Nieuwboer
Esteemed Contributor

Re: How to add alias in .profile

Hi you can also pu it in the .profile

alias ll="ls -l"
alias lla="ls -la"
alias ltr="ls -ltr"

but use dubble quote.

grtz. Mark
Senthil Prabu.S_1
Trusted Contributor

Re: How to add alias in .profile

Hi,
Setting alias in .profile as

alias ll="ls -l"
alias c=clear

should work.

I guess, the problem is that your shell is not updated with new .profile. Better close that session and start a new session or execute the following command;

#. .profile


HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Senthil Kumar .A_1
Honored Contributor

Re: How to add alias in .profile

Hi Sanjeev,

Did you logout and login again ?

Regards,
Senthil Kumar .A
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Senthil Prabu.S_1
Trusted Contributor

Re: How to add alias in .profile

Hi again,
Run the .profile file in your session again, to update the environment variables in your shell.
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Sanjeev gupta_2
Frequent Advisor

Re: How to add alias in .profile

Hi All,

I tried all, but couldn't work. I find out that problem is with shell as the shell assign to me in passwd file is /bin/sh.However I move from this shell to ksh in .profile, but it seems that when i put alias in .kshrc and then execute this .kshrc in .profile , it is executed by /bin/sh instead of ksh.After login the shell assgined to me is ksh(I swith to ksh in .profile ) so when i execute .kshrc or directly alias , it works. So i think .profile is executed by /bin/sh.
please put your thought on this so that I may sort out this issue.
Regards,
Sanjeev
Senthil Prabu.S_1
Trusted Contributor

Re: How to add alias in .profile

No, you are wrong. Even ksh will read the .profile file. So adding alias to ksh can be done through .profile.

To set alias, refer this link;
http://docs.hp.com/en/B2355-90046/ch18s02.html



HTH,
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Sanjeev gupta_2
Frequent Advisor

Re: How to add alias in .profile

Hi,
I checked it, If you are saying is correct then why same alias command which is working fine at command prompt, does not work when i put it in .profile, even when i put in different file and execute this file in .profile, it does not work.
Pl. suggest
Sanjeev gupta

Torsten.
Acclaimed Contributor

Re: How to add alias in .profile

Please post your alias example, so we can see what we are talking about.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Sanjeev gupta_2
Frequent Advisor

Re: How to add alias in .profile

alias ll="ls -alrt"
Senthil Kumar .A_1
Honored Contributor

Re: How to add alias in .profile

Hi Sanjeev,

If you want to work with ksh, do not put it in .profile, instead change your shell defnition in /etc/passwd file. This could be done by doing the following..

chsh -r files /usr/bin/ksh

Use finger command to check whether the change is implemented.

Regards,
Senthil Kumar .A
Let your effort be such, the very words to define it, by a layman - would sound like a "POETRY" ;)
Sยภเl Kย๓คг
Respected Contributor

Re: How to add alias in .profile

Hi,

Which is the OS, is it HPUX. If why are you trying to set alias to 'll'. This ll is a command which is equal to 'ls -l': Long list.

Try to alias with some other name like

alias LL='ls -alrt'

Regards,
Sunil
Your imagination is the preview of your life's coming attractions
Torsten.
Acclaimed Contributor

Re: How to add alias in .profile

Something goes wrong while passing the alias to your current shell.

How are you changing your shell in .profile?

To create an alias for "ll" should perfectly work.
You can check that with

# whence -v ll

this should give you

ll is an alias for ls -alrt

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Sanjeev gupta_2
Frequent Advisor

Re: How to add alias in .profile

this is sun box.
I'm writing /usr/bin/ksh in .profile to change the shell and it is perfectly working
MarkSyder
Honored Contributor

Re: How to add alias in .profile

Re the advice to change your login shell to ksh in /etc/passwd: if you are logging in as root DO NOT DO THIS! It will cause you all sorts of problems.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
rariasn
Honored Contributor

Re: How to add alias in .profile

Hi,

Edit user '.profile' and add alias. Sample:

# Define rm ALIAS.
alias rm="rm -i"

ran
Matti_Kurkela
Honored Contributor

Re: How to add alias in .profile

One thing to remember if you start one shell from another:
while the exported environment variables are inherited from the parent shell by the child shell, the alias definitions are not.

You must define your aliases in a file which is executed *every time* a new shell is started, not only when the user is logging in.

In HP-UX, /bin/sh executes /etc/profile and $HOME/.profile only at login, but if the ENV variable is set, the file described by the ENV variable is executed each time a new shell starts, whether it is a login situation or not.

If you use a setting like:
ENV=$HOME/.profile
export ENV
you must be careful with environment variable settings in .profile.
If you make additions to environment variable values (like PATH), the login shell will work fine, but the child shells may have the addition done twice.

For example, the login shell gets the standard PATH from /etc/profile, then executes something like "PATH=$PATH:/opt/some_application/bin" in .profile. The child shells get the already modified PATH, so if the .profile is executed again, the PATH value will look like "...:/opt/some_application/bin:/opt/some_application/bin". Grandchild shells get the addition done a third time, and so on.

Usually, this is ugly-looking but harmless. But in some situations (and particularly with variables other than PATH and MANPATH) it may cause problems.
MK
Peter Nikitka
Honored Contributor

Re: How to add alias in .profile

Hi,

note, that /bin/sh ist NOT the posix shell in Solaris as in HP-UX.
The alias command is not known in the simple Bourne shell.

Next, if you just call
/usr/bin/ksh
in your .profile, the execution of a new process is performed and obviously .profile is NOT reread again - else you would have created an infinite loop.
Any alias calls before would be useless, because ignored or set in another process.
Any aliases after that would be seen only after the termination of ksh.
Try 'exit' in your shell to check this.

Really setup a normal ksh environment via
ENV=$HOME/.kshrc
export ENV
and put your aliases there.

Even better is to change your login shell to ksh. On Solaris with NIS call:
passwd -r nis -e

For other authentication methods (-r files , ...) use the appropriate tag (man passwd).

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Bill Hassell
Honored Contributor

Re: How to add alias in .profile

Since this is a Sun problem and not HP-UX, a lot of the advice is HP-UX specific and may not apply. Are you actually running .profile when you login? To see if you are, put an echo line at the beginning of .profile, something like this:

echo "running .profile"

Then login. If you do not see "running .profile" then that's the problem. In HP-UX, if you use a terminal emulator from an Xwindow system, the default behavior is to ignore all profiles, a very bad behavior IMHO. If you are indeed using an Xwindow system to login, read the man page on the Xwindow system where you get your xterm (or dtterm or hpterm). Then look to see if there is an Xwindow resource called loginShell. IF so, you need to set that to true and now your emulator will actually login normally, meaning that /etc/profile and .profile will be run.


Bill Hassell, sysadmin
Alex Glennie
Honored Contributor

Re: How to add alias in .profile

I think BH may have hit the nail on the head, ie your login is under CDE or X.

CDE is the same on hpux as it is under Solaris wrt application resources so try running :

dtterm -ls

does the alias work now ?

if yes vi $HOME/.Xresources

add

*loginShell:True

exit CDE and try a dtterm again ?

see man dtterm for details