Skip to content

Commit

Permalink
add exampels
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothee-Cardoso authored May 9, 2021
1 parent c06a60e commit 2c75c76
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
# shell
# Shell

shell package to run powershell and bash with go.

## Powershell

```go
import "github.com/secman-team/shell"

// run a command
shell.PWSLCmd(`Write-Host "secman is 🔒"`)

// run a script
shell.PWSLCmd(`
$x = git config user.name
Write-Host $x
`)

// run a command with out
err, out, errout := shell.PWSLOut(`[System.Environment]::SetEnvironmentVariable("Path", $Env:Path + ";$SECMAN_PATH\bin", [System.EnvironmentVariableTarget]::User)`)

if err != nil {
log.Printf("error: %v\n", err)
fmt.Print(errout)
}

fmt.Print(out)
```

## Bash/Shell

```go
import "github.com/secman-team/shell"

// run a command
shell.ShellCmd(`echo "secman is 🔒"`)

// run a script
shell.ShellCmd(`
mood="👨‍💻"
if [ $mood != "😪" ]; then
echo "still coding"
fi
`)

// run a command with out
err, out, errout := shell.ShellOut(`curl --silent "https://api.github.com/repos/secman-team/secman/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'`)

if err != nil {
log.Printf("error: %v\n", err)
fmt.Print(errout)
}

fmt.Print(out)
```

0 comments on commit 2c75c76

Please sign in to comment.