How to execute commands in variables when zx? #1159
-
// /bin/bash: ls -a: command not found |
Beta Was this translation helpful? Give feedback.
Answered by
antongolub
Mar 24, 2025
Replies: 1 comment
-
Hey @Song-aff, This is an effect of $.quote. By default, zx brings some protection to avoid cmd mixing as params.
await $({quote: v => v})`${command}`
import {$} from 'zx'
const cmd = 'ls -a'
const p = $`echo hello && eval ${cmd}` |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
antongolub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
quote
eval