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

Single quotes prevent interpolation #4

Open
ngirard opened this issue Oct 18, 2020 · 5 comments
Open

Single quotes prevent interpolation #4

ngirard opened this issue Oct 18, 2020 · 5 comments

Comments

@ngirard
Copy link

ngirard commented Oct 18, 2020

let pwd = env::var("PWD").unwrap();
cmd!("echo 'Hello from {pwd}'").run()?;

produces

Hello from {pwd}

instead of the expected

Hello from /home/ngirard/....
@matklad
Copy link
Owner

matklad commented Oct 18, 2020

I wouldn't say that this is an explicitly designed behavior, but I think it is reasonable. The shell works that way, there's no interpolation in single quotes.

let pwd = env::var("PWD").unwrap();
cmd!("echo 'Hello from '{pwd}").run()?;

will do what you want

@ngirard
Copy link
Author

ngirard commented Oct 18, 2020

Well, I'm not sure it's the most readable & comfortable option...

Let's take another example: notify-send expects the string to be displayed to be given as a single argument.
What would then be the equivalent Xshell cmd! statement to the following shell command ?

notify-send "Hello from $PWD"

@matklad
Copy link
Owner

matklad commented Oct 18, 2020

cmd!(“notify-send 'Hello from '{PWD}“)

Adjacent tokens are concated into a single arg. But I do agree that this is kinda silly. I think I need to bite the bullet and implement proper escapensequences and double quoted strings, so that your example just works.

@ngirard
Copy link
Author

ngirard commented Oct 18, 2020

I think that would be a valuable improvement.

Thanks in advance !

@azzamsa
Copy link

azzamsa commented Sep 12, 2022

The shell works that way, there's no interpolation in single quotes

So it is okay to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants