New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

shell-tag

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shell-tag

Run shell commands inline in JavaScript with ES6 template strings

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
1.7K
23.61%
Maintainers
0
Weekly downloads
 
Created
Source

Because sometimes you want to write shell scripts with JavaScript instead of bash.

Uses a fork of shell-escape-tag to escape values.

Usage

import sh from 'shell-tag'

const lsOutput = sh`ls -1`

// => "index.js
// node_modules
// package.json
// readme.md
// test-helper
// test.js"

You can even use javascript variables inside your bash code!

import sh from 'shell-tag'

const str = 'say "what"'

const echoOutput = sh`echo ${str}`

// => say "what"

Throws errors if a non-0 exit code is returned. Otherwise, returns the string from stdout.

An async version is available:

import sh from 'shell-tag/async'

const str = 'say "what"'

(async() => {
	const echoOutput = await sh`cat package.json | grep name`

	// => '  "name": "shell-tag",\n'
})()

License

WTFPL

Keywords

es6

FAQs

Package last updated on 28 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts