Skip to content

Question: what is the "right" way to consume cue values inside a shell script #48

Closed

Description

@dubo-dubon-duponey
cake: "1\"2\n3"

oven: {
  string

  #dagger: compute: [
    {
     do: "fetch-container"
      ref: "busybox"
    },
    {
      do: "exec"
      args: ["sh", "-c", """
      # Option 1
      # echo "$foo" > /out
      # Option 2
      # echo "\(cake)" > /out
      """]
      dir: "/"
      env: foo: cake
    },
    {
      do: "export"
      source: "/out"
      format: "string"
    }
  ]
}

Option 1 will "work" - option 2 will fail (obviously?).

Is it fair to assume that direct references to cue values from inside a script will break and should absolutely be avoided (option 2), and that only option 1 is the right way to go? Or is there a better way to do this?

Activity

  1. dubo-dubon-duponey commented on Jan 19, 2021

    @dubo-dubon-duponey
    ContributorAuthor

    Adding that evidently, you could also do

          args: ["sh", "-c", """
          echo "1" > /out
          """, "--", cake]
    

    This is "better", as:

    • no ceremony declaring a bunch of env variables
    • escaping works fine

    ... but the syntax is really heavy handed for newcomers.

    Maybe, generally, Exec could be improved this way:

    a. "magic" stdout and "stderr" so that you do not have to monkey it out yourself.

    args: ["binary", "arg1", cuearg]
    stdout: true
    stderr: true
    

    ... would then work fine giving you stdout & stderr.

    b. have a different argument for scripts (alternatively, some magic to detect whether the first argument is a script or a binary

    
    script: ["""
    #!/usr/bin/env bash
    echo "$1" "$2"
    """, "arg1", cuearg]
    

    The rest is a documentation problem (discouraging people from using \(cuearg) inside script strings.

    2 cents.

  2. shykes commented on Apr 29, 2021

    @shykes
    Contributor

    Closing this in favor of github discussions.

  3. added a commit that references this issue on May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions