You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hledger/hledger.m4.md
+6-34Lines changed: 6 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -336,52 +336,24 @@ Many hledger arguments are [regular expressions] (described below), and these to
336
336
Some of those characters are `.`, `^`, `$`, `[`, `]`, `(`, `)`, `|`, and `\`.
337
337
When you don't want these to cause special effects, you can "regex-escape" them by writing `\` (a backslash) before them.
338
338
But since backslash is also special to the shell, you may need to also shell-escape the backslashes.
339
+
Note that `$` only has special meaning to the shell if followed by a word character indicating a variable name.
340
+
When appearing alone at the end of a word as in `cur:\\$` the dollar sign is not considered special and does not *have* ta be escaped.
339
341
340
342
Eg, in the bash shell, to match a literal `$` sign, you could write:
341
343
342
344
```cli
343
345
$ hledger balance cur:\\$
344
346
```
345
347
346
-
or:
347
-
348
-
```cli
349
-
$ hledger balance 'cur:\$'
350
-
```
348
+
The escape here is to pass through a literal escape, the dollar sign does not have to be escaped because it is at the end of a word and hence can't be interpreted as a shell variable.
351
349
352
-
(The dollar sign is regex-escaped by the backslash preceding it.
353
-
Then that backslash is shell-escaped by another backslash, or by single quotes.)
354
-
355
-
### Escaping add-on arguments
356
-
357
-
When you run an external add-on command with `hledger` (described below),
358
-
any options or arguments being passed through to the add-on executable lose one level of shell-escaping,
359
-
so you must add an extra level of shell-escaping to compensate.
360
-
361
-
Eg, in the bash shell, to run the `ui` add-on and match a literal `$` sign, you need to write:
350
+
Alternatively, use single quotes to avoid the special meanings of shell characters and see more visually what value will be passed through:
362
351
363
352
```cli
364
-
$ hledger ui cur:'\\$'
365
-
```
366
-
367
-
or:
368
-
369
-
```cli
370
-
$ hledger ui cur:\\\\$
353
+
$ hledger balance 'cur:\$'
371
354
```
372
355
373
-
If you are wondering why *four* backslashes:
374
-
375
-
-`$` is unescaped
376
-
-`\$` is regex-escaped
377
-
-`\\$` is regex-escaped, then shell-escaped
378
-
-`\\\\$` is regex-escaped, then shell-escaped, then both slashes are shell-escaped once more for hledger argument pass-through.
379
-
380
-
Or you can avoid such triple-escaping, by running the add-on executable directly:
381
-
382
-
```cli
383
-
$ hledger-ui cur:\\$
384
-
```
356
+
Here hledger will get a query string of `\$`, which is a regex escaped and hence will match a literal dollar sign.
0 commit comments