deno icon indicating copy to clipboard operation
deno copied to clipboard

Deno task doesn't accept {}

Open vixalien opened this issue 2 years ago • 10 comments

Trying to run a task with { or } fails:

// deno.json
{
  "tasks": {
    "slash": "echo {}",
  }
}
$ deno task slash
Task slash echo {}
error: Error parsing script 'slash'.

Caused by:
    Unexpected character.
      {}
      ~

It doesn't work no matter how hard I escape the braces.

The { and } are used in the bash function find -exec {} \; syntax.

vixalien avatar Oct 12 '23 17:10 vixalien

As a workaround, you can put the string in quotes:

{
  "tasks": {
    "slash": "echo '{}'",
  }
}

dsherret avatar Oct 13 '23 00:10 dsherret

when I do that, find can no longer work because the -exec parameter needs to end with exactly {};

On Fri, 13 Oct 2023, 02:38 David Sherret, @.***> wrote:

As a workaround, you can put the string in quotes:

{ "tasks": { "slash": "echo '{}'", } }

— Reply to this email directly, view it on GitHub https://github.com/denoland/deno/issues/20893#issuecomment-1760590526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJB5FCP4UCAETPUJ56ORDXLX7CEPLANCNFSM6AAAAAA556VSQU . You are receiving this because you authored the thread.Message ID: @.***>

vixalien avatar Oct 13 '23 02:10 vixalien

@vixalien can you show the actual example that's failing?

dsherret avatar Oct 13 '23 02:10 dsherret

Without single quotes:

$ deno task find
Task find find -regex '.*\.[tj]sx?' -exec grep -i class {} \;
error: Error parsing script 'find'.

Caused by:
    Unexpected character.
      {} \;
      ~

With single quotes:

$ deno task find
Task find find -regex '.*\.[tj]sx?' -exec grep -i class '{}' \;
/usr/bin/find: missing argument to `-exec'
$ 

mgenereu avatar Oct 13 '23 04:10 mgenereu

@vixalien , you can do the classic hacky nested shell. This worked for me.

{
  "tasks": {
    "find": "sh -c \"find -regex '.*\\.[tj]sx?' -exec grep -i class {} \\;\""
  }
}

mgenereu avatar Oct 13 '23 04:10 mgenereu

It seems also the escaping of ; does not work. The following does though:

{
  "tasks": {
    "find": "find -regex '.*\\.[tj]sx?' -exec grep -i class '{}' ';'"
  }
}

dsherret avatar Oct 13 '23 07:10 dsherret

@dsherret , I don't know why deno tasks is choking on {} in the first place. If you don't think it's a bug and just an escaping issue, can you lightly explain and I can add something to the deno task documentation?

mgenereu avatar Oct 13 '23 16:10 mgenereu

It is a bug.

dsherret avatar Oct 14 '23 00:10 dsherret

yes I think it's a bug. I'm not sure why it would not accept {} in the first place too.

vixalien avatar Oct 16 '23 15:10 vixalien

Getting that issue as well:

"dc:clean": "docker ps -a -q --filter=\"name=app\" | xargs -I {} docker stop {} && docker ps -a -q --filter=\"name=app\" | xargs -I {} docker rm -f {}",
error: Error parsing script 'dc:clean'.

Caused by:
    Unexpected character.
      {} docker stop {} && docker ps -a -q --filter="name=app" | x
      ~

Single quote '{}' does not help.

soundstep avatar Oct 18 '24 15:10 soundstep