Code quality improvements from /u/Sigg3net
/u/Sigg3net suggested these changes on Reddit:
Nice! I have some friendly comments about your script.
Backticks are superseeded by
$( ), e.g.CWD=`dirname "$0"`to
CWD=$( dirname "$0" )and quote your variables, both in
PROFILE_NAME=nordvpnand
if [ ! -d $OPENVPN_DIR ]; thenThere's also some unsafe(?) assumptions regarding executables. I would change this:
NODE=/usr/bin/nodeto rather check for node in path:
if ! NODE=$( command -v node ) ; then echo "Error: Can't find node in PATH" ; exit 1 ; fiThis both saves $NODE as you want, but also gives an error if node is not in PATH (it should be).
If you want a quick analysis of your shellscript, please check out shellcheck. It has saved my behind many times.