go-sh icon indicating copy to clipboard operation
go-sh copied to clipboard

How use and operator?

Open MeGaPk opened this issue 7 years ago • 5 comments

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?

MeGaPk avatar Sep 13 '16 14:09 MeGaPk

No. & is not allowed by go-sh

codeskyblue avatar Sep 14 '16 00:09 codeskyblue

@codeskyblue Maybe add new command like: session.And("...") ? Or write to documentation, that operator && not supported?

MeGaPk avatar Sep 14 '16 07:09 MeGaPk

pr welcome

codeskyblue avatar Oct 09 '16 05:10 codeskyblue

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
)

mraaroncruz avatar Dec 15 '17 23:12 mraaroncruz

"rm -f" never returns error...

tgulacsi avatar Aug 11 '19 04:08 tgulacsi