1833574 Members
3787 Online
110061 Solutions
New Discussion

setting aliases

 
SOLVED
Go to solution
Fred Ruffet
Honored Contributor

setting aliases

Hi !

I need to set an alias for a command, but it is not exported even when using -x. Here is what I have :

#alias -x foo=yeah
#alias -x
autoload='typeset -fu'
command='command '
foo=yeah
functions='typeset -f'
history='fc -l'
integer='typeset -i'
local=typeset
nohup='nohup '
r='fc -e -'
stop='kill -STOP'
suspend='kill -STOP $$'
type='whence -v'
#sh
#alias
autoload='typeset -fu'
command='command '
functions='typeset -f'
history='fc -l'
integer='typeset -i'
local=typeset
nohup='nohup '
r='fc -e -'
stop='kill -STOP'
suspend='kill -STOP $$'
type='whence -v'

Isn't my alias supposed to exist in subshells ?
And where are other aliases set ? (can't find them in profile)
--

"Reality is just a point of view." (P. K. D.)
11 REPLIES 11
Sanjay Kumar Suri
Honored Contributor

Re: setting aliases

alias are set in .shrc or .kshrc. alias are availabe in subshells also.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Ralph Grothe
Honored Contributor

Re: setting aliases

Maybe you still have to assign the environment variable ENV to the file where your alias definitions reside, and export it.
Madness, thy name is system administration
Mark Grant
Honored Contributor

Re: setting aliases

From the sh-posix man page

"Exported aliases remain in effect for subshells but must be reinitialized for separate invocations of the shell"
Never preceed any demonstration with anything more predictive than "watch this"
Fred Ruffet
Honored Contributor

Re: setting aliases

They don't seem to. I have aliases that are not set in .kshrc, .shrc, .profile, /etc/profile... and aliases do not appear in subshells (try to launch a new shell, and you'll see) even if I use "alias -x".
--

"Reality is just a point of view." (P. K. D.)
Sanjay Kumar Suri
Honored Contributor

Re: setting aliases

Very trivial but

Have you set the alias as below?

alias dir=ls

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Fred Ruffet
Honored Contributor

Re: setting aliases

Of course, I tried alias "dir"="ls". but when I launch sh, I don't see it anymore.

I'll try to use ENV variable to set up aliases for each new shell (even if I think alias -x should have worked :)
--

"Reality is just a point of view." (P. K. D.)
Jean-Luc Oudart
Honored Contributor
Solution

Re: setting aliases

Hi tried myself

alias -x jlo='pwd'
alias jlo2='ls -C1'
~~~~~~~~~~~~~~~~~~~~~~~~
alias in current shell => I have both in the list
~~~~~~~~~~~~~~~~~~~~~~~~
sh : create new shell => I have none of them
~~~~~~~~~~~~~~~~~~~~~~~~
create a script that list the aliases.
when I run the script , this is a new process
I have jlo but not jlo2

~~~~~~~~~~~~~~~~

So this is exported for a process but not for a new shell
For this you need to setup your ENV variable :
ENV If this parameter is set, parameter substitution is
performed on the value to generate the path name of the
script to be executed when the shell is invoked (see
the "Invocation" subsection). This file is typically
used for alias and function definitions.

Regards,
Jean-Luc
fiat lux
Fred Ruffet
Honored Contributor

Re: setting aliases

Do your script to list aliases include a #!/bin/sh line ?
--

"Reality is just a point of view." (P. K. D.)
Sanjay Kumar Suri
Honored Contributor

Re: setting aliases

I have following observation:

alias set in .shrc are availabe in child shell where alias set at $prompt are not.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
MarkSyder
Honored Contributor

Re: setting aliases

I have a file alias.ksh which contains my aliases. When I log in I run . alias.ksh.

The . before the command makes sure the aliases are available in the current shell.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Chia-Wei
Advisor

Re: setting aliases

Let's say your aliases are stored in file .alias.ksh

You need to add this line to your .profile :
export ENV=.alias.ksh

With this it will work.