Reputation: 817
The question is really simple. I want to create an alias, e.g.alias short="echo a$1"
. When I run short k
I get the output a k
, but what I actually want is ak
. How can I achieve that?
Upvotes: 0
Views: 620
Reputation: 4332
Try
alias short="echo a$1b"
>> ab k
Its not working like you think it is. The $1 is getting resolved before the set to alias is finished is finished, so therefore:
alias -p
>> alias short='echo ab'
But bigger picture you are confusing an alias
which is a dumb replacement of one token with another and a function
which is meant to take parameters in the fashion you are trying to do here. What you probably are after is
function short(){ echo "a$1"; }
short k
>> ak
N.B. If you have already defined alias, don't forget to unalias
it because the alias with get run before the function.
Upvotes: 4