Q:

how to change directory to a path stored in variable bash

I'm trying to change the CD to a path stored in a variable. The variable gets its value from text stored in a file. 
This gets the value inside the text file:
devdir=$(<\$HOME/devdir.txt)
cd $devdir

Inside the text file is the text: $HOME/bin
The error I get is:
/bin/dev: line 41: cd: $HOME/bin: No such file or directory

This is the result of trying to use the variable, compared to manually typing it:

UPDATE:
This is the snippet of Bash given with the improvement given by fabiotk, which seems to yield no result when it is within the script, however it works fine when run in the cmd window...Snippet
Here is the entire script so far: script
and here is me running the given line on its own, then running the script showing it doesn't work inside: enter image description here

A:

Try this:
cd $(eval "echo \"$(cat $HOME/devdir.txt)\"");

or:
eval "cd \"$(cat $HOME/devdir.txt)\"";

It will change the directory inside the script session that you are running. If you run ./script it won't cd externally

