Here is a part of my .bashrc file:
echo_pwd () {
echo `pwd`
}
export echo_pwd="`echo_pwd`/"
I created a new function echo_pwd that prints the path of the current directory and a new environment variable that contains the current directory followed by a slash. Therefore, I can use my environment variable in command line (such as $PWD).
However, this environment variable doesn't expand correctly and always refers to my home directory:
~/Documents$ env | grep echo_pwd
echo_pwd=/home/pierre/
~/Documents$
What can I do to make my environment variable expands correctly?
Note: this is obviously a dummy example. In my specific use case, the echo_pwd is a much more complex function.
echo $(stuff)? – Kamil Maciorowski Apr 01 '20 at 07:50$HOMEdirectory, the correct directory path is assigned to the variableecho_pwd. Are you not re-executing it when changing directories? Also, why don't you use$PWD? – Kusalananda Apr 01 '20 at 07:51cd,$echo_pwdwill always be/home/pierre. Therefore, is there a way to have an environment variable (or something else) that can change dynamically? – Pierre Apr 01 '20 at 08:03$(echo_pwd), I don't have to create an environment variable and its value is always updated when I change of directory. – Pierre Apr 01 '20 at 08:05