0

I have been create a sh file to automate next spark instalations. In the file I am putting the following steps:

sudo apt install openjdk-8-jdk scala  -y
java -version; javac -version; scala -version; git --version
wget https://downloads.apache.org/spark/spark-3.1.3/spark-3.1.3-bin-hadoop3.2.tgz 
tar xvf spark-*
sudo mv spark-3.1.3-bin-hadoop3.2 /opt/spark
echo "export SPARK_HOME=/opt/spark" >> ~/.bashrc
echo "export PATH=$PATH:$SPARK_HOME/bin:$SPARK_HOME/sbin" >> ~/.bashrc

Up to line 6, the process works as expected, but at the last step, instead of writing exactly what I requested, it is converting the environment variables to their real values and writing the real values to bashrc. I need to write in the bashrc file exactly what I requested in the echo, without converting the environment variables.

Is it possible?

Danilo Rodrigues
  • 373
  • 3
  • 17
  • Do you want line 7 to evaluate the value of `PATH` at the time your sh file executes or at the time `.bashrc` executes? If the latter, then it's `\$PATH` not `$PATH`. The escaping of `SPARK_HOME` is irrelevant since it's effectively a constant. – Jeff Holt Sep 10 '22 at 02:39
  • 1
    Variable references expand inside double-quotes; use single-quotes (or escape the `$` characters) to keep them from expanding. Actually, I'd use single *and* double-quotes: `echo 'export PATH="$PATH:$SPARK_HOME/bin:$SPARK_HOME/sbin"' >> ~/.bashrc` -- the single-quotes prevent premature expansion of variables, and then when .bashrc is run, the double-quotes make sure the value doesn't get word-split (only matters in some non-bash shells, but IMO it's better to be safe). – Gordon Davisson Sep 10 '22 at 05:02

0 Answers0