Operating System - HP-UX
1831831 Members
3406 Online
110031 Solutions
New Discussion

How do you define an alias?

 
SOLVED
Go to solution
Angie_1
Regular Advisor

How do you define an alias?

How do I define an alias for a command? When I type "alias" I see a bunch already defined but can't figure out where its pulling those definitions from. Looked in .login.

Angie
19 REPLIES 19
Victor BERRIDGE
Honored Contributor

Re: How do you define an alias?

Hi Angie
It depends of you shell - using ksh its just
alias='your alias'

e.g.
alias ll='ls -al'

All the best
Victor

P.S.
If you want to use them at each connection then put your aliases in a .kshrc and modify your .profile to take account: ENV= $HOME/.kshrc;export ENV
Angie_1
Regular Advisor

Re: How do you define an alias?

I am not using Korn shell... POSIX shell... when I type ps it says "sh" as the shell running. Assuming that is HPs POSIX shell?

I want the aliases to be saved forever, don't want to have to redefine them each time.

Thank you,
Angie
A. Clay Stephenson
Acclaimed Contributor

Re: How do you define an alias?

Aliases are easy to define:

alias lsetc='ls -l /etc'

That's all there is to it. I suspect the aliases you are seeing are those that are compiled into the shell rather than being read in in .profile.

The built-in aliases include
autoload='typeset -fu'
integer='typeset -i'
to name a few.

These built-ins can be redefined or unset if you like. Man sh-posix for details.
If it ain't broke, I can fix that.
Victor BERRIDGE
Honored Contributor

Re: How do you define an alias?

Seems to work in a same way,
put the aliases in .profile
just alias aliasname=''


You should see them (I hope) at next connection


All the best
Victor
Angie_1
Regular Advisor

Re: How do you define an alias?

If I set the aliases like you mentioned, will that store them permanently????

Also, the ones that I see are the following:

nohup
stop
suspend
function
integer
local
autoload
command

So maybe you answered the question then as to why I can't find where they are pulling from.

Thanks - Angie
Angie_1
Regular Advisor

Re: How do you define an alias?

I placed an alias in my .profile file and its not picking it up. But when I type it manually at the command line the following

alias m='more'

it works fine. The .profile file is in my home directory on the NFS mount. What is going on???

Thanks... Angie
Victor BERRIDGE
Honored Contributor

Re: How do you define an alias?

I remember going through this once and forgot about it (that means trying to understand what is happening...) and remembered a workaround I did at the time until I would solve (if it can be...):
- Create a alias file my_alias
- put all the alias you want there
- add in your .profile:
. $HOME/my_alias

Then test:
this works at new connection time...

All the best
Victor

Sanjay_6
Honored Contributor

Re: How do you define an alias?

Hi angie,

to make the alias change permanent, add it to your profile. You need to logout and login again to make it work.

Hope this helps.

Regds
A. Clay Stephenson
Acclaimed Contributor

Re: How do you define an alias?

Have you logged in again so that your .profile is read?

The other possibility is that you are using CDE and have not set DTSOURCEPROFILE=true in your .dtprofile.
If it ain't broke, I can fix that.
Kent Ostby
Honored Contributor

Re: How do you define an alias?

Angie .. after typing them in your .profile,
you can make it active for that session by typing:

. ./.profile

(that's 3 "."s)

OR your next login should make it active.

Best regards,

Oz
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Victor BERRIDGE
Honored Contributor

Re: How do you define an alias?

Hi Angie,
I just tested: with posix you have no problem with alias in .profile, not true for ksh where you will have to do the previous my_alias...

As mentionned it workes at next connection only

All the best
Victor
Angie_1
Regular Advisor

Re: How do you define an alias?

Ok I am trying this out now and will let you know here in a bit. Also the DTSOURCEPROFILE was commented out in the .dtprofile file.

I uncommented it.

Thank you all for your input and let you know.

Angie
Angie_1
Regular Advisor

Re: How do you define an alias?

Ok I should have mentioned. I am running Exceed and it takes me into CDE. Placing the alias commands in .profile OR .dtprofile still doesn't make it stay permanent. These 2 files are both located in my home directory on the NFS mount. I do completely log out of the system too and then back in.

I did leave the DTSOURCEPROFILE=true uncommented in that .dtprofile file.

I wonder why this isn't working.

Angie
Sanjay_6
Honored Contributor
Solution

Re: How do you define an alias?

Hi angie,

Maybe this link from itrc would help,

http://www1.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000063204439

The itrc doc id is KBRC00000416.

Hope this helps.

Regds
Angie_1
Regular Advisor

Re: How do you define an alias?

Ok thanks, will go take a look at it.

Wish it was more simple though!

Angie
Geoff Wild
Honored Contributor

Re: How do you define an alias?

These are "built in" aliases - from man ksh (posix is ksh and more):

The following exported aliases are compiled into the shell but can be
unset or redefined:

autoload='typeset -fu'
false='let 0'
functions='typeset -f'
hash='alias -t -'
history='fc -l'
integer='typeset -i'
nohup='nohup '
r='fc -e -'
stop='kill -STOP'
suspend='kill -STOP $$'
true=':'
type='whence -v'

You can put in .profile or .kshrc.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Bill Hassell
Honored Contributor

Re: How do you define an alias?

The problem is with your connection. You're not on the HP-UX computer, but on a PC that knows nothing about Xwindows. You have to run an emulator (Hummingbird's Exceed) which then pretends to be an Xterminal (used to be a lot of those around in the old days).

The key is that when you start a terminal window in CDE, you are bypassing *all* the 'normal' Unix processes. If you run telnet from your PC to HP-UX, you'll login and /etc/profile plus your local .profile will be run automatically. CDE figures you don't need any of that so the default is to ignore it all. The .dtprofile file cannot specify /etc/profile so you'll neever get your settings from /etc/profile, just .profile when DTSOURCEPROFILE value is set true.

So the default aliases (which are listed in the man page for sh-posix and ksh) are the ones you posted. Any additional aliases defined in .profile will be set when you use telnet (and no Xwindows).

If you must use CDE, then you need to put a special file in your $HOME directory (same place as .profile) called .Xdefaults which sets the default values (Xresources) for Xwindow programs like dtterm and xterm. Put the following lines into a file called $HOME/.Xdefaults on the HP-UX server:

*LoginShell: True

Now when you start a CDE sessions and then a dtterm or xterm or hpterm window, a normal Unix login will take place and both /etc/profile and .profile will be run.

But the real problem is that you're using CDE to manage your PC's desktop, possibly not what you want at all. If you are just starting terminal windows like dtterm or xterm, don't bother starting a CDE session and Exceed at all. Instead, start a terminal emulator like the Windows telnet program or use a free terminal emulator like QCTerm. You'll get a normal login


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: How do you define an alias?

The problem is with your connection. You're not on the HP-UX computer, but on a PC that knows nothing about Xwindows. You have to run an emulator (Hummingbird's Exceed) which then pretends to be an Xterminal (used to be a lot of those around in the old days).

The key is that when you start a terminal window in CDE, you are bypassing *all* the 'normal' Unix processes. If you run telnet from your PC to HP-UX, you'll login and /etc/profile plus your local .profile will be run automatically. CDE figures you don't need any of that so the default is to ignore it all. The .dtprofile file cannot specify /etc/profile so you'll neever get your settings from /etc/profile, just .profile when DTSOURCEPROFILE value is set true.

So the default aliases (which are listed in the man page for sh-posix and ksh) are the ones you posted. Any additional aliases defined in .profile will be set when you use telnet (and no Xwindows).

If you must use CDE, then you need to put a special file in your $HOME directory (same place as .profile) called .Xdefaults which sets the default values (Xresources) for Xwindow programs like dtterm and xterm. Put the following lines into a file called $HOME/.Xdefaults on the HP-UX server:

*LoginShell: True

Now when you start a CDE sessions and then a dtterm or xterm or hpterm window, a normal Unix login will take place and both /etc/profile and .profile will be run.

But the real problem is that you're using CDE to manage your PC's desktop, possibly not what you want at all. If you are just starting terminal windows like dtterm or xterm, don't bother starting a CDE session and Exceed at all. Instead, start a terminal emulator like the Windows telnet program or use a free terminal emulator like QCTerm. You'll get a normal login like any Unix box with all the aliases and env settings.


Bill Hassell, sysadmin
Angie_1
Regular Advisor

Re: How do you define an alias?

Ok thank you all for explaining. I am going to have to do what was the last thing posted. A very lengthy explanation...WOW! Thank you! If I want to use Exceed and get this to work right looks like I need to go that route.

Appreciate all the responses.

Angie