Skip to content

Commit

Permalink
docs: add documentation on substitution and shell variable expansion (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
lucas-deangelis authored Nov 28, 2023
1 parent dfdf644 commit f132c19
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f132c19

Please sign in to comment.