0

I have a line in my ec2 instance user data that is seen below

cat <<EOT >> $HOME/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HADOOP_HOME=$HOME/hadoop
export HADOOP_CONF=$HADOOP_HOME/etc
export PATH=$PATH:$JAVA_HOME:$HADOOP_HOME/bin
EOT

It is supposed to append to the ~/.bashrc file while inferring variable itself, but what is appended to the ~/.bashrc file looks like

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HADOOP_HOME=/home/ubuntu/hadoop
export HADOOP_CONF=/etc
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin::/bin

The HADOOP_HOME variable works fine but the HADOOP_CONF and PATH variable is not what it supposed to be. My guess is it wasn't able to infer $HADOOP_HOME in both cases.

What can I do about this?

I've tried separating it like this

cat <<EOT >> $HOME/.bashrc
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HADOOP_HOME=$HOME/hadoop
EOT

cat <<EOT >> $HOME/.bashrc
export HADOOP_CONF=$HADOOP_HOME/etc
export PATH=$PATH:$JAVA_HOME:$HADOOP_HOME/bin
EOT

I've also tried to surround the $HADOOP_HOME in quotes too

Temmyzeus
  • 36
  • 2
  • 3
    You need to either quote the here-document delimiter (i.e. `<<'EOT'`) or escape the `$` characters to keep the shell from expanding the variable references before sending the document to `cat`. See ["How to cat <> a file containing code?"](https://stackoverflow.com/questions/22697688/how-to-cat-eof-a-file-containing-code) – Gordon Davisson Feb 13 '23 at 06:10

0 Answers0