title: how to change directory to a path stored in variable bash
body: <p>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. </p>
  
  <p>This gets the value inside the text file:</p>
  
  <pre><code>devdir=$(&lt;\$HOME/devdir.txt)
  cd $devdir
  </code></pre>
  
  <p>Inside the text file is the text: <code>$HOME/bin</code></p>
  
  <p>The error I get is:</p>
  
  <pre><code>/bin/dev: line 41: cd: $HOME/bin: No such file or directory
  </code></pre>
  
  <p>This is the result of trying to use the variable, compared to manually typing it:</p>
  
  <p><a href="https://i.stack.imgur.com/9QcFo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9QcFo.png" alt="screen shot of text so you can&#39;t copy/paste it"></a></p>
  
  <p>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...<a href="https://i.stack.imgur.com/6Sgmr.png" rel="nofollow noreferrer">Snippet</a></p>
  
  <p>Here is the entire script so far: <a href="https://i.stack.imgur.com/Hmqhg.png" rel="nofollow noreferrer">script</a>
  and here is me running the given line on its own, then running the script showing it doesn't work inside: <a href="https://i.stack.imgur.com/dO1Bo.png" rel="nofollow noreferrer">enter image description here</a></p>