Skip to content

Instantly share code, notes, and snippets.

@ichikaway
Created October 11, 2018 03:10
Show Gist options
  • Save ichikaway/f0b93a4578f5153839de05d921925dec to your computer and use it in GitHub Desktop.
Save ichikaway/f0b93a4578f5153839de05d921925dec to your computer and use it in GitHub Desktop.
bash parser sample with docker

bash parser sample with docker

https://github.com/vorpaljs/bash-parser

docker pull node:8.9.4-alpine
docker run -d --name node-alpine -it node:8.9.4-alpine
docker exec -it node-alpine /bin/sh

vi sample.js

var util = require('util');
const parse = require('bash-parser');
const ast = parse("/bin/?'c'ho$u 't'es't'");
console.log(util.inspect(ast, {colors: true, depth:10}));

node sample.js

{ type: 'Script',
  commands: 
   [ { type: 'Command',
       name: 
        { text: '/bin/?\'c\'ho$u',
          expansion: 
           [ { loc: { start: 11, end: 12 },
               parameter: 'u',
               type: 'ParameterExpansion' } ],
          type: 'Word' },
       suffix: [ { text: 'test', type: 'Word' } ] } ] }
docker stop node-alpine
docker rm node-alpine
docker images
docker image rm node-alpine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment