diff --git a/bin/README.md b/bin/README.md index 8ee002555..b0d92e28c 100644 --- a/bin/README.md +++ b/bin/README.md @@ -38,6 +38,12 @@ Here are some scripts which don't use hledger directly, but might be useful to h (For more, see also: [plaintextaccounting.org > Software](https://plaintextaccounting.org#software)). +### ledgereval + +[`ledgereval`](https://github.com/simonmichael/hledger/blob/master/bin/ledgereval +is a helper for evaluating Ledger value expressions. +It's useful eg when converting amount expressions like `(1 USD + 2 USD)` to simple amounts. + ### pricehist [pricehist](https://pypi.org/project/pricehist) is useful for downloading market prices / conversion rates; recommended. diff --git a/bin/ledgereval b/bin/ledgereval new file mode 100755 index 000000000..9acd82bde --- /dev/null +++ b/bin/ledgereval @@ -0,0 +1,8 @@ +#!/bin/sh +# ledgereval [EXPR] - evaluate a Ledger value expression +# This runs `ledger eval`, but also accepts standard input, and does not add a newline. +# It's useful eg when converting Ledger's amount expressions to simple amounts. +# Decimal places can be important, eg ledgereval '0.01 USD / 2' vs ledgereval '0.010 USD / 2'. + +expr="${*:-$(cat)}" +printf '%s' "$(ledger eval "$expr")"