How to alias an export in bash

Sre*_*ala 7 bash alias export

I am trying to set an env variable which I can use to do relative directory chains. I am trying to do it the following way but cant get it to work. How do I do it?

alias sroot="export SROOT="$PWD""
alias drumit="cd $SROOT/abc/def/drumit"
Run Code Online (Sandbox Code Playgroud)

If I type sroot, it takes the alias but when i type drumit, it gives me an error saying

bash: cd: /abc/def/drumit: No such file or directory
Run Code Online (Sandbox Code Playgroud)

Looks like when the shell was launched it takes $SROOT as . Appreciate any help.

Thanks

Kei*_*ith 6

Your $PWD and $SROOT variables are being expanded at the time you define the aliases, not when you are using them. Put a \ in front of them to escape them while they are defined.

alias sroot="export SROOT="\$PWD""
alias drumit="cd \$SROOT/abc/def/drumit"
Run Code Online (Sandbox Code Playgroud)