Operating System - HP-UX
1827321 Members
3986 Online
109961 Solutions
New Discussion

Re: Ksh Alias parameters.

 
Pheroz Tengra
Advisor

Ksh Alias parameters.

I wanted to pass parameters to an alias, but it gives errors. Some had suggested to issue a set +u would do the trick, but so far no luck.
If someone has played around with the KSH aliases any help would be appreciated.
5 REPLIES 5
Jeff Machols
Esteemed Contributor

Re: Ksh Alias parameters.

#alias l='ls -l'
#l .profile

.profile is an argument
Uday_S_Ankolekar
Honored Contributor

Re: Ksh Alias parameters.

Mark Greene_1
Honored Contributor

Re: Ksh Alias parameters.

use -x if you want the alias exported to sub-shells; maybe try eval if the alias is complex:

alias -x lsl = "ls -l |$PAGER"

HTH
--
mark
the future will be a lot like now, only later
Deshpande Prashant
Honored Contributor

Re: Ksh Alias parameters.

HI
If you define an alias
#10="ls -lR"
Then use
#10 /tmp to list contents of /tmp

Thanks.
Prashant.

Take it as it comes.
Gregory Fruth
Esteemed Contributor

Re: Ksh Alias parameters.

It would help if you provided an example and
the error message you get when you try it.

As far as I know, ksh aliases can only be used
as the other posters described, i.e.

alias 'copy=cp'

Now you can say:

copy this that

and it behaves like:

cp this that

Perhaps what you want is to be able to do
something like this:

copy this that

and have it behave like:

cp this that the_other

where "the_other" is hard-coded into the
alias. I don't think ksh aliases can do that.

Perhaps you should set up a function
(subroutine) in your .kshrc or .profile.
Then the function's arguments are
available in $*. Example:

function copy {
cp $* the_other
}

On the other hand, csh aliases can use !* construct.
Example:

alias copy 'cp \!* the_other'

Good luck!