[kwlug-disc] Sanity check of shell scripting approach

William Park opengeometry at yahoo.ca
Wed Apr 21 11:14:15 EDT 2021


It would be helpful if you give a short example, like
     jq .appDomain < file

On 4/20/21 10:14 PM, Mikalai Birukou via kwlug-disc wrote:
> 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?
>
>
> _______________________________________________
> kwlug-disc mailing list
> kwlug-disc at kwlug.org
> https://kwlug.org/mailman/listinfo/kwlug-disc_kwlug.org





More information about the kwlug-disc mailing list