Skip to content

Commit 917e5bb

Browse files
committed
;doc:Special characters: edits [#2468]
1 parent 1ad6f30 commit 917e5bb

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

hledger/hledger.m4.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ certain characters have special meaning and sometimes need to be "escaped" or "q
280280
by prefixing backslashes or enclosing in quotes.
281281

282282
If you are able to minimise the use of special characters in your data, you won't have to deal with this as much.
283-
For example, you could use `-` or `_` instead of spaces in account names,
283+
For example, you could use hyphen `-` or underscore `_` instead of spaces in account names,
284284
and you could use the `USD` currency code instead of the `$` currency symbol in amounts.
285285

286286
But if you prefer to use spaced account names and `$`, it's fine.
287287
Just be aware of this topic so you can check this doc when needed.
288-
(Note it is written mainly for unix systems; some details might need to be adapted if you're on Windows.)
288+
(These examples are mostly tested on unix; some details might need to be adapted if you're on Windows.)
289289

290290
### Escaping shell special characters
291291

@@ -299,24 +299,29 @@ So for example, to match an account name containing spaces, like "credit card",
299299
$ hledger register credit card
300300
```
301301

302-
Instead, enclose the name in quotes:
302+
Instead, enclose the name in single quotes:
303303
```cli
304304
$ hledger register 'credit card'
305305
```
306306

307-
Single quotes are the most reliable. Or use double quotes if you want your shell to treat `$` as a variable interpolation, as in:
307+
On unix or in Windows powershell, if you use double quotes your shell will silently treat `$` as variable interpolation.
308+
So you should probably avoid double quotes, unless you want that behaviour, eg in a script:
308309
```cli
309310
$ hledger register "assets:$SOMEACCT"
310311
```
311312

312-
On unix systems (but not Windows), a backslash before the space can also work:
313+
But in an older Windows CMD.EXE window, you must use double quotes (not single quotes or backslash):
313314
```cli
314-
$ hledger register credit\ card
315+
C:\Users\Me> hledger register "credit card"
315316
```
316317

317-
On Windows systems, if you are using a Command window rather than Powershell, use double quotes (not single quotes or backslash).
318+
On unix or in Windows powershell, as an alternative to quotes you can write a backslash before each special character:
319+
```cli
320+
$ hledger register credit\ card
321+
```
318322

319-
Since hledger's query arguments are [regular expressions] (described below), you can also fill that gap with `.` which matches any character:
323+
Finally, since hledger's query arguments are [regular expressions] (described below),
324+
you could also fill that gap with `.` which matches any character:
320325
```cli
321326
$ hledger register credit.card
322327
```
@@ -337,6 +342,7 @@ For example, a balance report that uses a `cur:` query restricting it to just th
337342
$ hledger balance cur:\\$
338343
```
339344
Explanation:
345+
340346
1. Add a backslash `\` before the dollar sign `$` to protect it from regular expressions (so it will be matched literally with no special meaning).
341347
2. Add another backslash before that backslash, to protect it from the shell (so the shell won't consume it).
342348
3. `$` doesn't need to be protected from the shell in this case, because it's not followed by a word character; but it would be harmless to do so.

0 commit comments

Comments
 (0)