Skip to content

How to execute commands in variables when zx? #1159

Closed Answered by antongolub
Song-aff asked this question in Help needed
Discussion options

You must be logged in to vote

Hey @Song-aff,

This is an effect of $.quote. By default, zx brings some protection to avoid cmd mixing as params.
But you're able to override this behaviour and accept the risks:

  • Set a custom quote
await $({quote: v => v})`${command}`
  • Apply bash eval
import {$} from 'zx'

const cmd = 'ls -a'
const p = $`echo hello && eval ${cmd}`

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by antongolub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants