Issue
I am pretty new to bash, and I want to include an env for bash aliases.. I want to do something like the following
alias foo="bar $(baz)"
So that I could do something like the following
> baz=40
> foo
and foo will expand to the command bar 40
. Currently the above does not work because $(baz) is expanded while making the alias. Do I have to wrap this inside a function or something?
Solution
You need to use single quotes ('
) to prevent bash from expanding the variable when creating the alias:
$ alias foo='echo "$bar"'
$ bar="hello"
$ foo
hello
Answered By - Kenneth Hoste Answer Checked By - Willingham (WPSolving Volunteer)