Skip to content

How would I pipe commands with no hardcoding of command strings? #32

Closed

Description

@redragonx

Hi, I would like to know how you can combine commands without hardcoding the actual cmd in the macro?

Not sure how escaping works in these cases.

Rough Example:

        let post_cmd  = "grep 'blah' | another_cmd"
        let output_raw = self.someVarEval();

        let data = run_fun!(echo "$output_raw" | $post_cmd );

When I run the above in full code. I get the following output error:

No such file or directory (os error 2)

Activity

  1. rust-shell-script commented on Sep 2, 2021

    @rust-shell-script
    Owner

    You can construct command string in your way and pass it to bash:

    let cmd_str = ....;
    let data = run_fun!(bash -c $cmd_str)?;
    

    It is not encouraged to do things like this, since it could introduce command injection and also you need to make the correct quotes. But anyway you are already doing things like that, so take your own risk.

  2. Repository owner locked and limited conversation to collaborators on Sep 2, 2021
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions