Skip to content

Commit e76a2b0

Browse files
alerquesimonmichael
authored andcommitted
docs: Correct documentation about shell escapes
1 parent 3c731ae commit e76a2b0

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

hledger/hledger.m4.md

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -336,52 +336,24 @@ Many hledger arguments are [regular expressions] (described below), and these to
336336
Some of those characters are `.`, `^`, `$`, `[`, `]`, `(`, `)`, `|`, and `\`.
337337
When you don't want these to cause special effects, you can "regex-escape" them by writing `\` (a backslash) before them.
338338
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.
339341

340342
Eg, in the bash shell, to match a literal `$` sign, you could write:
341343

342344
```cli
343345
$ hledger balance cur:\\$
344346
```
345347

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.
351349

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:
362351

363352
```cli
364-
$ hledger ui cur:'\\$'
365-
```
366-
367-
or:
368-
369-
```cli
370-
$ hledger ui cur:\\\\$
353+
$ hledger balance 'cur:\$'
371354
```
372355

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.
385357

386358
### Escaping in other situations
387359

0 commit comments

Comments
 (0)