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

missing quotation marks #29

Open
bigwasp opened this issue Aug 4, 2023 · 1 comment
Open

missing quotation marks #29

bigwasp opened this issue Aug 4, 2023 · 1 comment

Comments

@bigwasp
Copy link

bigwasp commented Aug 4, 2023

Just tried nim-2.0.0 on Linux Mint 21.2 (Ubuntu 22.04 based)

import shell

shell:
  one:
    mkdir foo
    pushd foo
    echo "Hallo\nWorld" > test.txt
    pipe:
      cat test.txt
      grep H
    popd
    rm foo/test.txt
    rmdir foo

It seems that the quotation marks got lost.
Have i done something wrong?

Just compiled with nim c {file,nim}

Throws following:

ShellCmd: mkdir foo && pushd foo && echo Hallo
World > test.txt && cat test.txt | grep H && popd && rm foo/test.txt && rmdir foo
shell> /bin/sh: 1: pushd: not found
shell> /bin/sh: 2: World: not found
Error when executing: mkdir foo && pushd foo && echo Hallo
World > test.txt && cat test.txt | grep H && popd && rm foo/test.txt && rmdir foo
err> 
@Vindaar
Copy link
Owner

Vindaar commented Aug 6, 2023

Thanks for the report!

Hmm, I think it's a mix of two things:

  1. I must have written this example before we switched to startProcess. Using startProcess we're not running in a normal terminal (so using bash for example), but rather with /bin/sh. pushd and popd are specific bash (and other posix extending terminal emulator) features. So that's why it says pushd: not found. That's a regression in some sense, of course. Need to think about this.
  2. it really seems like I broke the handling of strings. I guess in the past this correctly redirected to text.txt with two lines. In order for it to work, I now need to manually hand an explicit string:

So this works:

import shell

shell:
  one:
    mkdir foo
    cd foo
    "echo \"Hallo\nWorld\" > test.txt"
    pipe:
      cat test.txt
      grep H
    cd ".."
    rm foo/test.txt
    rmdir foo

I suppose I changed the string handling to make precisely this work. The idea being that a Nim string should just be handed "as is" in terms of the content to the shell. The example implies however, that the entire thing is handed as written to the shell. The latter is convenient in some cases (like here), but restricting in others (in the more common ones). Because we really need to be able to overwrite the limitations of the Nim grammar for many practical uses cases.

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

2 participants