FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sh/shell/example_test.go at master · HeyTool/sh · GitHub
HeyTool
/
sh
Public
forked from
mvdan/sh
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sh
/
shell
/
example_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (45 loc) · 1.12 KB
Breadcrumbs
sh
/
shell
/
example_test.go
Copy path
File metadata and controls
54 lines (45 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2018, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information
package
shell_test
import
(
"fmt"
"mvdan.cc/sh/v3/shell"
)
func
ExampleExpand
() {
env
:=
func
(
name
string
)
string
{
switch
name
{
case
"HOME"
:
return
"/home/user"
}
return
""
// leave the rest unset
}
out
,
_
:=
shell
.
Expand
(
"No place like $HOME"
,
env
)
fmt
.
Println
(
out
)
out
,
_
=
shell
.
Expand
(
"Some vars are ${missing:-awesome}"
,
env
)
fmt
.
Println
(
out
)
out
,
_
=
shell
.
Expand
(
"Math is fun! $((12 * 34))"
,
nil
)
fmt
.
Println
(
out
)
// Output:
// No place like /home/user
// Some vars are awesome
// Math is fun! 408
}
func
ExampleFields
() {
env
:=
func
(
name
string
)
string
{
switch
name
{
case
"foo"
:
return
"bar baz"
}
return
""
// leave the rest unset
}
out
,
_
:=
shell
.
Fields
(
`"many quoted" ' strings '`
,
env
)
fmt
.
Printf
(
"%#v
\n
"
,
out
)
out
,
_
=
shell
.
Fields
(
"unquoted $foo"
,
env
)
fmt
.
Printf
(
"%#v
\n
"
,
out
)
out
,
_
=
shell
.
Fields
(
`quoted "$foo"`
,
env
)
fmt
.
Printf
(
"%#v
\n
"
,
out
)
// Output:
// []string{"many quoted", " strings "}
// []string{"unquoted", "bar", "baz"}
// []string{"quoted", "bar baz"}
}
Back
|
FazBrowse Home
|
New Git URL