[kwlug-disc] Sanity check of shell scripting approach

Mikalai Birukou mb at 3nsoft.com
Tue Apr 20 22:14:43 EDT 2021


Sometimes, while in shell, I want to do manipulations that are simple in 
node, and I have no idea how to do in shell. I find myself with 
functions like:

app_domain_from_manifest() {
     local manifest="$1"
     node -e "
         const m = fs.readFileSync('$manifest', { encoding: 'utf8' });
         const appDomain = JSON.parse(m).appDomain.trim();
         if (!appDomain) { throw new Error('appDomain field is not a 
string'); }
         console.log(appDomain);
     " || exit $?
}

Couple of lines passed to node -e.

Is it insane?

Do you do similar with python?

What's your milage?





More information about the kwlug-disc mailing list