sh expects the name of a script to run as its argument. You don't run sh './test.sh test1 test2' at a shell, you run sh ./test.sh test1 test2. The equivalent to that in Go is:
// KINDA BAD: Doesn't let the script choose its own interpreter
cmd, err := exec.Command("/bin/sh", "./test.sh", "test1", "test2")
If you were passing a shell script as an argument, that would be akin to the shell command sh -c './test.sh test1 test2' -- notice the -c argument. It's very bad practice (introduces serious security bugs), and you shouldn't ever do this, but if you were going to, it would look like:
// VERY BAD: Introduces serious security bugs if arguments are parameterized
cmd, err := exec.Command("/bin/sh", "-c", "./test.sh test1 test2")
But you shouldn't do any of that. Change your script to have a shebang:
#!/bin/sh
param1=$1
param2=$2
echo "$param1"
echo "$param2"
...save it as yourscript (no .sh!), set it to have executable permissions (chmod +x yourscript), and then run:
// GOOD: Lets your script choose its own interpreter
cmd, err := exec.Command("./yourscript", "test1", "test2")
shshould never be used to run abashfile. sh and bash are two different shells -- even on operating systems where they're symlinked, starting bash under the nameshdisables some of its features.#!/bin/sh(if it's really ashscript instead of abashscript), give it executable permissions, and then startexec.Command('./test.sh', "test1", "test2"). (Ideally, you shouldn't have a.shextension on the filename either -- see commandname extensions considered harmful for an extensive essay on the topic; using extensions means you can't change your script's interpreter without making the extension misleading or also changing every caller).