I am new to bash programming and I am trying to setup a bash script, and I require to store the value of the path of the script, but as I can see, it gets lost.
#!/bin/bash
dir = "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "$dir"
echo "
|------------------------------------|
|------------------------------------|
| |
|Welcome to ec2 setup!!! Let's begin |
| |
|------------------------------------|
|------------------------------------|
"
echo "
/-----------------------------
Do you want to install nodejs?
-----------------------------/"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Enter the version number, eg; 8, 9"
read version
curl -sL https://deb.nodesource.com/setup_$version.x | sudo -E bash
sudo apt-get install -y nodejs
echo "Node version installed is $(node -v)"; break;;
No ) break;;
esac
done
echo "$dir"
echo "
/-----------------------------
Do you want to install mongodb?
-----------------------------/"
select yn in "Yes" "No"; do
case $yn in
Yes ) sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo service mongod start; break;;
No ) break;;
esac
done
echo "$dir"
When I run this script, echo "$dir"
prints nothing, except for at the start of the script.
What is it am I missing here?
Also, later in the code, I have to change directories, so how do I go about maintaining th reference to the initial directory?