Skip to content

Commit 05f38ff

Browse files
committed
use <<<
1 parent 761f201 commit 05f38ff

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

book.org

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,21 @@ Iversonian [[https://www.jsoftware.com/papers/tot.htm#1.2][suggestivity]] that g
13771377

13781378
Some more advanced tutorials [[https://programminghistorian.org/en/lessons/json-and-jq][here]] and [[https://remysharp.com/drafts/jq-recipes][here]].
13791379

1380+
** use jq . <<<"$var"
1381+
Newlines aren't allowed in json strings, and you might get a jq
1382+
error like:
1383+
1384+
"parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 148, column 99"
1385+
1386+
Sometimes, strings inside json might have encoded newlines like =\n=. If you would use
1387+
1388+
=echo $var | jq .= , bash would interpolate the \n inside the json
1389+
string and when it gets to jq, it's an invalid json.
1390+
1391+
If instead you use =echo -E=, or =<<<"$var"=, things go smoothly.
1392+
1393+
=jq . <<<"$var"=
1394+
13801395
** pass flags as a splatted array
13811396
There's quite a bit to chew on this example. First of all, the core
13821397
pattern is to build up your commandline options with an array, and

0 commit comments

Comments
 (0)