@@ -280,12 +280,12 @@ certain characters have special meaning and sometimes need to be "escaped" or "q
280
280
by prefixing backslashes or enclosing in quotes.
281
281
282
282
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,
284
284
and you could use the ` USD ` currency code instead of the ` $ ` currency symbol in amounts.
285
285
286
286
But if you prefer to use spaced account names and ` $ ` , it's fine.
287
287
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.)
289
289
290
290
### Escaping shell special characters
291
291
@@ -299,24 +299,29 @@ So for example, to match an account name containing spaces, like "credit card",
299
299
$ hledger register credit card
300
300
```
301
301
302
- Instead, enclose the name in quotes:
302
+ Instead, enclose the name in single quotes:
303
303
``` cli
304
304
$ hledger register 'credit card'
305
305
```
306
306
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:
308
309
``` cli
309
310
$ hledger register "assets:$SOMEACCT"
310
311
```
311
312
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) :
313
314
``` cli
314
- $ hledger register credit\ card
315
+ C:\Users\Me> hledger register " credit card"
315
316
```
316
317
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
+ ```
318
322
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:
320
325
``` cli
321
326
$ hledger register credit.card
322
327
```
@@ -337,6 +342,7 @@ For example, a balance report that uses a `cur:` query restricting it to just th
337
342
$ hledger balance cur:\\$
338
343
```
339
344
Explanation:
345
+
340
346
1 . Add a backslash ` \ ` before the dollar sign ` $ ` to protect it from regular expressions (so it will be matched literally with no special meaning).
341
347
2 . Add another backslash before that backslash, to protect it from the shell (so the shell won't consume it).
342
348
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