I added an alias:
$ alias anyalias="echo kallel"
If I execute:
$ anyalias
kallel
it executes the echo
command without any problem.
Now, if I define a variable in this way:
$ var="anyalias"
and then execute with this way:
$ $var
-ash: anyalias: not found
Then I got a shell error.
How I can make $var
running the command defined in the anyalias
alias?
I m not looking to change the way of calling $var
. But I m looking for a way of changing the definition of the alias or export it.
Instead of alias consider using function:
Safer is to store the call of function in an array (will store arguments also, if needed):
That's because alias expansion is performed previous to parameter expansion:
Command-line Processing
As you can see, you can go through the process again with
eval
, which is not recommended.Instead, you can use some alternatives as the one by @anubhava.
Example
Again, use
eval
carefully. It's just to illustrate the expansion process.