Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[$ Shell] not working with variable #9192

Closed
truongan07 opened this issue Mar 2, 2024 · 3 comments
Closed

[$ Shell] not working with variable #9192

truongan07 opened this issue Mar 2, 2024 · 3 comments
Labels
bug Something isn't working shell Something to do with Bun as a shell

Comments

@truongan07
Copy link

What version of Bun is running?

1.0.29+a146856d1

What platform is your computer?

Linux 6.3.6-arch1-1 x86_64 unknown

What steps can reproduce the bug?

import { $ } from 'bun';

// [case: 1] working
// const shell = $`cat 110kb.json | grep 2489678843`;

// [case: 2] not working
const string = 'cat 110kb.json | grep 2489678843';
const shell = $`${string}`;

await shell;

Download json file for testing: https://drive.google.com/file/d/1jEe5Pzr2wn21o-U8z3q02OJh3231S9oN/view?usp=drive_link

What is the expected behavior?

[case: 2] work

What do you see instead?

bun: command not found: cat 110kb.json | grep 2489678843

Additional information

No response

@truongan07 truongan07 added the bug Something isn't working label Mar 2, 2024
@jakeg
Copy link
Contributor

jakeg commented Mar 2, 2024

I believe you need to escape with

await $`${{raw: str}}`

With your test code:

import { $ } from 'bun'

// [case: 1] - no need to escape
const a = $`echo hello`
await a

// [case: 2] - doesn't work as not escaped
const str1 = 'echo hello'
await $`${str1}`

// [case: 3] - works when escaping
const str2 = 'echo hello'
await $`${{raw: str2}}`

And you can see case 3 works (but case 2 doesn't):

image

@Electroid
Copy link
Contributor

You need to escape it, as described.

@Electroid Electroid closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2024
@Electroid Electroid added the shell Something to do with Bun as a shell label Mar 2, 2024
@truongan07
Copy link
Author

@jakeg Thank you for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working shell Something to do with Bun as a shell
Projects
None yet
Development

No branches or pull requests

3 participants