From 8e61965af6fb7f45c2a56fd0a32c8dc16b69750c Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 17 Jun 2018 01:18:49 -0400 Subject: [PATCH 1/6] brace expansion tests --- test.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test.sh b/test.sh index 13138c8..972579b 100755 --- a/test.sh +++ b/test.sh @@ -134,6 +134,17 @@ test_read_sleep() { assert_equals "$((result+1))" "$SECONDS" } +test_braces_expansion() { + printf -v result %s {a,{q,x}}c + assert_equals "$result" "acqcxc" +} + +test_numeric_sequence() { + printf -v result '%s ' {1..10} + assert_equals "$result" "1 2 3 4 5 6 7 8 9 10 " +} + + test_bar() { result="$(bar 50 10)" assert_equals "${result//$'\r'}" "[----- ]" From 0b5a77f459a867c9c86194d6a6f45c41a4c36f6d Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 17 Jun 2018 01:20:08 -0400 Subject: [PATCH 2/6] rename functions --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 972579b..15effd4 100755 --- a/test.sh +++ b/test.sh @@ -134,12 +134,12 @@ test_read_sleep() { assert_equals "$((result+1))" "$SECONDS" } -test_braces_expansion() { +test_brace_expansion() { printf -v result %s {a,{q,x}}c assert_equals "$result" "acqcxc" } -test_numeric_sequence() { +test_brace_expansion_numeric_sequence() { printf -v result '%s ' {1..10} assert_equals "$result" "1 2 3 4 5 6 7 8 9 10 " } From f504d4618ab82a6c19ad45b46d20aa8b70892967 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 17 Jun 2018 01:20:27 -0400 Subject: [PATCH 3/6] delete newline --- test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test.sh b/test.sh index 15effd4..0991eac 100755 --- a/test.sh +++ b/test.sh @@ -144,7 +144,6 @@ test_brace_expansion_numeric_sequence() { assert_equals "$result" "1 2 3 4 5 6 7 8 9 10 " } - test_bar() { result="$(bar 50 10)" assert_equals "${result//$'\r'}" "[----- ]" From 920988deb0baea12ba4bdba2bc3a6cb957eadf97 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 17 Jun 2018 14:25:59 -0400 Subject: [PATCH 4/6] removed needless tests and added an example using braces expansion to loop over files explicitly referenced --- README.md | 5 +++++ test.sh | 10 ---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f3c9e35..766da98 100644 --- a/README.md +++ b/README.md @@ -674,6 +674,11 @@ for dir in ~/Downloads/*/; do printf '%s\n' "$dir" done +# Leverage brace expansion to loop, explicit reference +for file in /path/to/parentdir/{fil1,file2,subdir/file3}; do + printf '%s\n' "$file" +done + # Iterate recursively. shopt -s globstar for file in ~/Pictures/**/*; do diff --git a/test.sh b/test.sh index 0991eac..13138c8 100755 --- a/test.sh +++ b/test.sh @@ -134,16 +134,6 @@ test_read_sleep() { assert_equals "$((result+1))" "$SECONDS" } -test_brace_expansion() { - printf -v result %s {a,{q,x}}c - assert_equals "$result" "acqcxc" -} - -test_brace_expansion_numeric_sequence() { - printf -v result '%s ' {1..10} - assert_equals "$result" "1 2 3 4 5 6 7 8 9 10 " -} - test_bar() { result="$(bar 50 10)" assert_equals "${result//$'\r'}" "[----- ]" From 181aca448b100c056cb25c60ffb2f8c7e32a9eac Mon Sep 17 00:00:00 2001 From: Ben White Date: Mon, 18 Jun 2018 10:38:02 +1000 Subject: [PATCH 5/6] switch $(uname) to $OSTYPE in case example --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0f2e97d..3563573 100644 --- a/README.md +++ b/README.md @@ -1376,17 +1376,21 @@ successful command. `:` always succeeds so we can abuse it to store the variable value. ```shell -# Example snippet from Neofetch. -case "$(uname)" in - "Linux" | "GNU"*) +# Modified snippet from Neofetch. +case "$OSTYPE" in + "darwin"*) + : "MacOS" + ;; + + "linux"*) : "Linux" ;; - *"BSD" | "DragonFly" | "Bitrig") + *"bsd"* | "dragonfly" | "bitrig") : "BSD" ;; - "CYGWIN"* | "MSYS"* | "MINGW"*) + "cygwin" | "msys" | "win32") : "Windows" ;; From cf3b473afa530e1386b21d82d23274db40c68d6a Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 17 Jun 2018 20:43:54 -0400 Subject: [PATCH 6/6] fix mispelling --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 766da98..889e0e3 100644 --- a/README.md +++ b/README.md @@ -675,7 +675,7 @@ for dir in ~/Downloads/*/; do done # Leverage brace expansion to loop, explicit reference -for file in /path/to/parentdir/{fil1,file2,subdir/file3}; do +for file in /path/to/parentdir/{file1,file2,subdir/file3}; do printf '%s\n' "$file" done