{"id":22669090,"url":"https://github.com/stjohnjohnson/shell-variables","last_synced_at":"2025-10-19T08:31:04.194Z","repository":{"id":18592084,"uuid":"21796636","full_name":"stjohnjohnson/shell-variables","owner":"stjohnjohnson","description":"Command-line service to read/write variables between shell processes","archived":false,"fork":false,"pushed_at":"2018-01-27T18:04:18.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-28T14:50:00.569Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.org/package/shell-variables","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stjohnjohnson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-13T17:58:45.000Z","updated_at":"2016-12-20T07:07:11.000Z","dependencies_parsed_at":"2022-09-24T12:47:09.222Z","dependency_job_id":null,"html_url":"https://github.com/stjohnjohnson/shell-variables","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stjohnjohnson%2Fshell-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stjohnjohnson%2Fshell-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stjohnjohnson%2Fshell-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stjohnjohnson%2Fshell-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stjohnjohnson","download_url":"https://codeload.github.com/stjohnjohnson/shell-variables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237091246,"owners_count":19253996,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T15:18:28.107Z","updated_at":"2025-10-19T08:31:03.863Z","avatar_url":"https://github.com/stjohnjohnson.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shell Variable Tunnel\n[![wercker status](https://app.wercker.com/status/e83ceea5fa3f0317c0f05b637590b9ef/m \"wercker status\")](https://app.wercker.com/project/bykey/e83ceea5fa3f0317c0f05b637590b9ef)\n\nDon't you just hate running multiple shell commands but not being able to properly read any data back other than exit codes and standard out?  No?  Really?  I guess it's a problem most people don't have, but I ended up having.  So I wrote this simple client/server system to be able to read/write variables from Node.JS to/from shell commands.\n\n## Install\n\nshell-variables should be added to your codebase as a dependency.  You can do this with:\n\n``` shell\n$ npm install --save shell-variables\n```\n\nAlternatively you can manually add it to your package.json file:\n\n``` json\n{\n  \"dependencies\" : {\n    \"shell-variables\": \"latest\"\n  }\n}\n```\n\nthen install with:\n\n``` shell\n$ npm install\n```\n\n## Usage\n\nThe purpose of this is to have a service available to all child processes so that they can read/write data.  Here's a simple example where we write back to the Node.JS process:\n\n```JavaScript\nvar spawn = require('child_process').spawn,\n    shellVariables = require('shell-variables'),\n    server,\n    spawnInstance;\n\nserver = new shellVariables.Server({\n    foo: 'bar'\n});\n\nserver.start(function () {\n    // Set the \"coconut\" variable from the command-line\n    spawnInstance = spawn('shell_variables.js', ['set', 'coconut', 'monkey'], {\n        stdio: 'inherit',\n        env: process.env\n    });\n    spawnInstance.on('close', function (code) {\n        console.log('child process exited with code ' + code);\n        console.log('value of coconut: ', server.get('coconut'));\n        console.log('value of variables: ', server.variables);\n        server.stop();\n    });\n});\n```\n\n### Dot Notation\n\nAll variables read via the server, client, or cmd-line interface can be accessed at varying levels of depth via dot-notation.  An example of this is here:\n\n```JavaScript\nvar obj = {\n        foo: {\n            bar: {\n                baz: 15\n            }\n        }\n    };\nconsole.log(server.get('foo.bar.baz'));\n// Outputs 15\n```\n\n### Server\n\nCreating a new server has two optional arguments:\n - `existingVariables` - Some existing object map\n - `timeout` - Timeout for the service in milliseconds\n\nFour methods are available to use:\n - `start(callback)` - takes a callback that returns the URL of the service\n - `stop(callback)` - takes a callback that returns nothing really\n - `get(field)` - returns the value of that field (dot-notation)\n - `set(field, value)` - sets the value of that field (dot-notation)\n\nTwo variables are available as well:\n - `variables` - the current fields and values\n - `url` - the URL of the service\n\n### Client\n\nCreating a client (if you wanted to do so inside a child node process) is easy as well.  It has two optional arguments:\n - `serverUrl` - the URL of the server service (by default read from the environment)\n - `timeout` - Timeout for the service in milliseconds\n\nTwo methods are available to use:\n - `get(field)` - returns the value of that field (dot-notation)\n - `set(field, value)` - sets the value of that field (dot-notation)\n\n### Command-line tool\n\nThe command-line is just as easy as the client if not more as it includes its own documentation:\n\n``` bash\n$ shell_variables.js\n\nUsage: shell_variables.js \u003ccommand\u003e [options]\n\ncommand\n  get     retrieve data from the variable tunnel\n  set     write data to the variable tunnel (accepts pipes)\n\nOptions:\n   --server    URL of the server, usually $(VARIABLE_TUNNEL_URL)\n   --timeout   Timeout in milliseconds  [5000]\n   --json      Return everything in JSON format  [false]\n```\n\n#### Get\n\n``` bash\n$ shell_variables.js get\n\nshell_variables.js get \u003cfield\u003e [options]\n\nfield     dot-notation field to retrieve value\n\nOptions:\n   --server    URL of the server, usually $(VARIABLE_TUNNEL_URL)\n   --timeout   Timeout in milliseconds  [5000]\n   --json      Return everything in JSON format  [false]\n```\n#### Set\n\n``` bash\n$ shell_variables.js set\n\nUsage: shell_variables.js set \u003cfield\u003e [value] [options]\n\nfield     dot-notation field to write values to\nvalue     value to set (if not provided, reads from STDIN)\n\nOptions:\n   --server    URL of the server, usually $(VARIABLE_TUNNEL_URL)\n   --timeout   Timeout in milliseconds  [5000]\n   --json      Return everything in JSON format  [false]\n   --format    Force the set value into specific formats (json, boolean, float, integer, string)  [string]\n\n```\n## License\n\n[MIT](http://opensource.org/licenses/MIT) © [St. John Johnson](http://stjohnjohnson.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstjohnjohnson%2Fshell-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstjohnjohnson%2Fshell-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstjohnjohnson%2Fshell-variables/lists"}