go-sh
go-sh copied to clipboard
How use and operator?
Hello! I have question. I have this code:
session := sh.NewSession()
session.SetTimeout(time.Second * 30)
session.ShowCMD = true
session.SetDir(repositoryPath)
session.Command(
"rm", "-f", archiveFile, "&&",
"git", "archive", branchName, "--format", "tar", "--output", archiveFile,
)
And debug message:
[golang-sh]$ rm -f /tmp/archive.tar && git archive origin/master --format tar --output /tmp/archive.tar
But second command not executed...
If i remove "rm", "-f", archiveFile, "&&",
Its work, but i need this "&&" operator.
What mistake?
No. & is not allowed by go-sh
@codeskyblue Maybe add new command like:
session.And("...")
?
Or write to documentation, that operator && not supported?
pr welcome
This is very old, but maybe it will help someone and get this issue closed.
Here's a way to use a &&
./my_script.sh
#!/bin/bash
archive_file=$1
branch=$2
rm -f ${archive_file} && git archive ${branch} --format tar --output ${archive_file}
session := sh.NewSession()
session.SetTimeout(time.Second * 30)
session.ShowCMD = true
session.SetDir(repositoryPath)
session.Command(
"./my_script.sh", archiveFile, branchName
)
"rm -f" never returns error...