Skip to content

Commit

Permalink
Merge pull request #113 from xushiwei/q
Browse files Browse the repository at this point in the history
gsh demo
  • Loading branch information
xushiwei committed Mar 9, 2024
2 parents 89d3fde + 1e8bfea commit 6611387
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -23,3 +23,6 @@ _testmain.go
*.exe
*.test
*.prof

testgsh*
gop_autogen*.go
7 changes: 4 additions & 3 deletions gsh/README.md
Expand Up @@ -13,7 +13,7 @@ Yes, now you can write `shell script` in Go+. It supports all shell commands.

## Usage

First, let's create a file named `./example.gsh` and write the following code:
First, let's create a file named [example.gsh](demo/hello/example.gsh) and write the following code:

```coffee
mkdir "testgsh"
Expand Down Expand Up @@ -89,10 +89,11 @@ exec "GOOS=linux GOARCH=amd64 go install ."

### Retrieve environment variables

You can get the value of an environment variable through `${XXX}`. For example:
You can get the value of an environment variable through `${XXX}` or `$XXX`. For [example](demo/envvar/example.gsh):

```coffee
ls "${HOME}"
echo ${HOME}
ls $HOME
```

You can also use `exec` command through `$XXX`:
Expand Down
2 changes: 2 additions & 0 deletions gsh/demo/envvar/example.gsh
@@ -0,0 +1,2 @@
echo ${HOME}
ls $HOME
23 changes: 23 additions & 0 deletions gsh/demo/example/example.gsh
@@ -0,0 +1,23 @@
type file struct {
name string
fsize int
}

mkdir! "testgsh"

mkdir "testgsh2"
lastErr!

mkdir "testgsh3"
if lastErr != nil {
panic lastErr
}

capout => { ls }
println output.fields

capout => { ls "-l" }
files := [file{flds[8], flds[4].int!} for e <- output.split("\n") if flds := e.fields; flds.len > 2]
println files

rmdir "testgsh", "testgsh2", "testgsh3"
3 changes: 3 additions & 0 deletions gsh/demo/exec/example.gsh
@@ -0,0 +1,3 @@
exec "go", "version"
exec "ls $HOME"
exec "mkdir testgsh"
1 change: 1 addition & 0 deletions gsh/demo/hello/example.gsh
@@ -0,0 +1 @@
mkdir "testgsh"

0 comments on commit 6611387

Please sign in to comment.