Shell String Split

Having some trouble with this operation, found that you can use string replacement syntax to also split a string to array:

NPM_VER=$(npm -v) # 6.12.1
NPM_VER=(${NPM_VER//./ }) # Split on '.' as delimiter

echo "${NPM_VER[0]}" # 6
echo "${NPM_VER[1]}" # 12
echo "${NPM_VER[2]}" # 1

Shell commands with Node

Running CLI Node scripts, capture the return value of a shell command:

const execSync = require('child_process').execSync;
const nodeVer = execSync('node -v', { encoding: 'utf8' });

Shell command reports in the CLI:

const execSync = require('child_process').execSync;
execSync('npm -g ls', { stdio: 'inherit' });