I'm learning bash scripting and was trying to write a script that checks if nodeJs is installed, and if it is not, then install it.
NodeJs is installed in my system. Before messing it up, the output I got when executing node -v
was v4.x.x.
Then, I was following this post and I wrote the following code in my script:
#!/bin/bash
if [ command -v node >/usr/bin/node 2>&1 ]; then
# save node version in a string variable.
STRING=cat | node -v
echo "NodeJs version: " ${STRING}
else
echo "NodeJs not found."
fi
I executed my script (testScript.sh) but now when I run node -v
the output I get is:
/usr/bin/node: line 1: ./testScript.sh:: No such file or directory
I cant figure out what I broke... any ideas? Thanks a lot.