From 4e794ecfde83b535b6871a449e34b07d89be2c60 Mon Sep 17 00:00:00 2001 From: Joshua Levy Date: Tue, 11 Aug 2015 10:14:34 -0700 Subject: [PATCH] More on brace expansion. Updates #116. Thanks also to the suggestion in #1. --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 14126b9..1979b8f 100644 --- a/README.md +++ b/README.md @@ -115,9 +115,8 @@ Notes: - In Bash, note there are lots of kinds of variable expansion. Checking a variable exists: `${name:?error message}`. For example, if a Bash script requires a single argument, just write `input_file=${1:?usage: $0 input_file}`. Arithmetic expansion: `i=$(( (i + 1) % 5 ))`. Sequences: `{1..10}`. Trimming of strings: `${var%suffix}` and `${var#prefix}`. For example if `var=foo.pdf`, then `echo ${var%.pdf}.txt` prints `foo.txt`. -- Shell brace expansion can help reduce having to re-type similar text. The command `echo foo{,bar,baz}` will expand to -`echo foo foobar foobaz`. This is helpful when copying/renaming files such as `cp somefile{,.bak}` which expands to -`cp somefile somefile.bak` or `mv some_{,absurdly_long_}filename` which expands to `mv some_filename some_absurdly_long_filename` +- Brace expansion using `{`...`}` can reduce having to re-type similar text and automate combinations of items. This is helpful in examples like `mv foo.{txt,pdf} some-dir` (which moves both files), `cp somefile{,.bak}` (which expands to +`cp somefile somefile.bak`) or `mkdir -p test-{a,b,c}/subtest-{1,2,3}` (which expands all possible combinations and creates a directory tree). - The output of a command can be treated like a file via `<(some command)`. For example, compare local `/etc/hosts` with a remote one: ```sh