0

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
1
  • 2
    You would be better off with a function Commented Feb 22, 2017 at 16:08

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.