Using variables when defining aliases in bashrc

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'

Leave a Reply

Your email address will not be published. Required fields are marked *