Using variables when defining aliases in bashrc Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Using variables when defining aliases in bashrc without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am trying to reuse alias variables while defining other aliases in .bashrc file as shown below:

alias cwd='cd /work/local/assignment1'
alias module1='$(cwd)/module1'

This does not work and I would like to know whether it is possible to use variables while defining aliases.

Any help is appreciated.

Answer

Your cwd is not a variable but an alias. You could instead do:

cwd='cd /work/local/assignment1'
alias module1='$cwd/module1'

As suggested by @StephenHarris, you may want to add the following to get your cwd working as usual:

alias cwd='$cwd'
We are here to answer your question about Using variables when defining aliases in bashrc - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji