From f132c19d4c2bca2865f20edbaf4e0406e1b5c817 Mon Sep 17 00:00:00 2001 From: Lucas De Angelis Date: Tue, 28 Nov 2023 22:14:56 +0100 Subject: [PATCH] docs: add documentation on substitution and shell variable expansion (#38) Using double quotes for the REPLACEMENT argument with capture group substitution in shells like Bash or zsh will not work as intended. For example, a "${1}" will be replaced by the content of the shell variable 1 before rnr can read them, resulting in no substitution. --- README.md | 1 + src/app.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6686e59..d58975f 100644 --- a/README.md +++ b/README.md @@ -478,6 +478,7 @@ rnr -f '(\w+)-(\d+).(\w+)' '${2}-${1}.${3}' ./* ├── 02-file.txt └── 03-file.txt ``` +__SHELL NOTE:__ In shells like Bash and zsh, make sure to wrap the `REPLACEMENT` pattern in single quotes. Otherwise, capture group indices will be replaced by expanded shell variables. #### Capture several named groups and swap them 1. Capture two digits as `number`. 2. Capture extension as `ext`. diff --git a/src/app.rs b/src/app.rs index dfe645d..7a19075 100644 --- a/src/app.rs +++ b/src/app.rs @@ -88,7 +88,7 @@ pub fn create_app<'a>() -> App<'a, 'a> { ) .arg( Arg::with_name("REPLACEMENT") - .help("Expression replacement") + .help("Expression replacement (use single quotes for capture groups)") .required(true) .validator_os(is_valid_string) .index(2),