• Uncategorized

About linux : Reference-variable-in-alias

Question Detail

I want to define an alias which references an environment variable in real time. For example, how can I make an alias to echo the value of N?

$ N=4
$ alias sayn="echo $N"
$ N=2
$ sayn
4

Question Answer

Since you define your alias using double quotes, the $N is expanded before definition and your alias actually is echo 4.

Try this :

$N=4
$alias sayn='echo $N'
$N=2
$sayn
2

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.