so my code looks like this , i have a function defined as the following :
func shellOut(command string) (string, string, error) {
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd := exec.Command("bash", "-c", command)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
return stdout.String(), stderr.String(), err
}
and a while later i am doing this.
t := "yoooooooooooo\"oo)(';#oooooooooooo"
out, stderr, err := shellOut("echo \"" + t + "\" | ./doOperation.sh")
if err != nil {
log.Printf("final error: %v\nstderr: %s", err, stderr)
}
fmt.Println(out)
but i am getting an error that looks like this:
2021/10/14 22:54:18 final error: exit status 1
stderr: bash: -c: line 838: syntax error near unexpected token `('
bash: -c: line 838: ` return "Symbol(" + String(void 0 === t ? "" : t) + ")_" + (++n + r).toString(36)'
and when i give the variable t a value like "yooooo" its gets executed nicely, so how can i pass a variable with any weird character into echo? is there a way to escape all bad character before passing it?