Why doesn't alias work in AIX (Korn shell, .profile)?
Solution 1
It does work.
The only difference I can see with my own .profile are the double quotes:
alias l="ls -l"
That line works for me in AIX with ksh as the shell.
Regarding the disconection and reconection... are you sure the default shell is ksh? Check your user in /etc/passwd.
Solution 2
.profile
is only read at login. Later modifications do not affect the current environment. You have to reload .profile
by means of:
- sourcing the file:
. .profile
(affects the current shell, not all shells) su -l <user>
(new login)- logout + login
Solution 3
The .profile
is not your shell configuration file, it's your login session settings file. It is only read by the shell started upon login, not other interactive shells started within your login session.
ksh
has no dedicated customization file per-se, but it treats the $ENV
variable as a path to a customization file for interactive shell sessions.
So you'd add something like:
ENV="$HOME/.kshrc" export ENV
to your ~/.profile
and:
alias 'l=ls -lrt'
to your ~/.kshrc
.
The change would only take effect at the next login.
Related videos on Youtube
jrara
Updated on September 18, 2022Comments
-
jrara almost 2 years
I have these files in my home directory:
drwxr-xr-x 3 meuser staff 256 Oct 12 13:11 . drwxr-xr-x 102 bin bin 4096 Sep 30 12:28 .. -rw------- 1 meuser staff 5349 Oct 11 20:44 .bash_history -rwx------ 1 meuser staff 466 Jun 26 22:12 .profile -rw------- 1 meuser staff 7074 Oct 12 13:11 .sh_history drwx------ 2 meuser staff 256 Aug 16 15:28 .ssh
My default shell is the Korn shell. When I tried to put an alias into
.profile
like this:alias l='ls -lrt'
and tried to run it after relogin:
$ l ksh: l: not found.
How to make this alias work?
-
Mikel over 10 yearsWhat happens when you run
. ./.profile
? -
G-Man Says 'Reinstate Monica' about 9 yearsAre you typing
l
in response to your$
shell prompt, or are you typing$l
?
-
-
jrara over 10 yearsThat does not seem to work. I changed my default shell to bash and relogin, and then it worked. So it is somehow related to korn shell.
-
Marco over 10 years@jrara Try adding
-l
to provide an login environemnt. -
G-Man Says 'Reinstate Monica' about 9 yearsNote that the question shows an error message coming from
ksh
. -
YoMismo about 9 years@G-Man My "It does work" in the answer means alias works in AIX (Read the title of the question). The rest of the answer explains why it didn't work in his case.