Skip to content

Commit

Permalink
Need to escape single quotes in bash, updated docs #1932
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Feb 2, 2024
1 parent 2473068 commit 6e21c9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/yqlib/doc/usage/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ fruit:
then
```bash
yq '.[] |(
( select(kind == "scalar") | key + "='" + . + "'"),
( select(kind == "seq") | key + "=(" + (map("'" + . + "'") | join(",")) + ")")
( select(kind == "scalar") | key + "='\''" + . + "'\''"),
( select(kind == "seq") | key + "=(" + (map("'\''" + . + "'\''") | join(",")) + ")")
)' sample.yml
```
will output
Expand Down Expand Up @@ -203,8 +203,8 @@ deep:
then
```bash
yq '.. |(
( select(kind == "scalar" and parent | kind != "seq") | (path | join("_")) + "='" + . + "'"),
( select(kind == "seq") | (path | join("_")) + "=(" + (map("'" + . + "'") | join(",")) + ")")
( select(kind == "scalar" and parent | kind != "seq") | (path | join("_")) + "='\''" + . + "'\''"),
( select(kind == "seq") | (path | join("_")) + "=(" + (map("'\''" + . + "'\''") | join(",")) + ")")
)' sample.yml
```
will output
Expand Down
2 changes: 1 addition & 1 deletion pkg/yqlib/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func documentInput(w *bufio.Writer, s expressionScenario) (string, string) {
writeOrPanic(w, "then\n")

if s.expression != "" {
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v'%v' %v\n```\n", envCommand, command, s.expression, files))
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v'%v' %v\n```\n", envCommand, command, strings.ReplaceAll(s.expression, "'", `'\''`), files))
} else {
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v%v\n```\n", envCommand, command, files))
}
Expand Down

0 comments on commit 6e21c9f

Please sign in to comment.