title: Can not write variable to any file in bash scripting using ~ in path?
body: <p>I'm writing bash script to automate java 8 installation and setting up home variable. Its a part of a big automation script.</p>
  
  <p>I have completed everything and able to print path of home variable. But I can't seem to write or append in any file when I'm using ~ in the path.</p>
  
  <p><strong>Example</strong></p>
  
  <p>Not work: echo "$writeit" >> ~/.bashrc
  Works: echo "$writeit" >> /home/geek/.bashrc</p>
  
  <p>Output of my script states empty JAVA_HOME variable
  <a href="https://i.stack.imgur.com/vaxgC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vaxgC.png" alt="Output"></a></p>
  
  <p>These commands works perfect if I indivisibly run in terminal.
  <a href="https://i.stack.imgur.com/QfawW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QfawW.png" alt="enter image description here"></a></p>
  
  <p>CODE</p>
  
  <pre><code>#!/bin/bash
  
  LOG_FILE="java.log"
  touch $LOG_FILE
  exec &gt; &gt;(tee $LOG_FILE) 2&gt;&amp;1
  echo "Java Installation Succeded"
  echo $JAVA_HOME
  javapath=$(ls -l `which java` | grep -oP "(?&lt;=\-\&gt;\s)(.*)")
  javahome=$(ls -l ${javapath} | grep -oP "(?&lt;=\-\&gt;\s\/)(.*)(?=bin)")
  writeit="export JAVA_HOME=${javahome}"
  echo "$writeit"
  echo "$writeit" &gt;&gt; ~/.bashrc
  source ~/.bashrc
  echo 'JAVA_HOME is set'"${JAVA_HOME}"
  </code></pre>