Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: real time alias?



On 17/03/18 03:47 PM, Stephane Chazelas wrote:
2018-03-15 10:51:47 -0700, Ray Andrews:

You can always use eval:

    $ f() { eval 'myalias 1'; echo done; }
    $ alias myalias=echo; f
    1
    done
    $ alias myalias=return; f
    $ echo $?
    1


That's exactly what I had in mind:

Script:

alias alias1="echo one"
function test1 () { eval alias1 }

alias alias1="echo two"
test1
alias alias1="echo three"
test1
alias alias1="echo four"
test1

Output:

two
three
four

... so, bearing in mind what Bart said about aliases being able to carry any sort of foul up of syntax, one must be careful since whatever is in the alias at parsing will be checked for sanity, but after that I'd expect one is on one's own.



Messages sorted by: Reverse Date, Date, Thread, Author