aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-19 19:45:56 +0100
committerAbigail <abigail@abigail.be>2021-01-19 19:45:56 +0100
commit8efd5eca4066257d8d39aa1f25481b09e8bc7689 (patch)
tree4b66e1782ed295614425e6d60ffc8b994347d8f7
parentaafab4118e1ed9b94a7f2c16cf4457d79ab53f77 (diff)
downloadperlweeklychallenge-club-8efd5eca4066257d8d39aa1f25481b09e8bc7689.tar.gz
perlweeklychallenge-club-8efd5eca4066257d8d39aa1f25481b09e8bc7689.tar.bz2
perlweeklychallenge-club-8efd5eca4066257d8d39aa1f25481b09e8bc7689.zip
Bash solution for week 96, part 1
-rw-r--r--challenge-096/abigail/README.md1
-rw-r--r--challenge-096/abigail/bash/ch-1.sh21
2 files changed, 22 insertions, 0 deletions
diff --git a/challenge-096/abigail/README.md b/challenge-096/abigail/README.md
index b80b3476b1..3582807374 100644
--- a/challenge-096/abigail/README.md
+++ b/challenge-096/abigail/README.md
@@ -21,6 +21,7 @@ Output: "family same the of part are Raku and Perl"
### Solutions
* [AWK](awk/ch-1.awk)
+* [bash](sh/ch-1.sh)
* [C](c/ch-1.c)
* [lua](lua/ch-1.lua)
* [Node.js](node/ch-1.js)
diff --git a/challenge-096/abigail/bash/ch-1.sh b/challenge-096/abigail/bash/ch-1.sh
new file mode 100644
index 0000000000..9122fae4e0
--- /dev/null
+++ b/challenge-096/abigail/bash/ch-1.sh
@@ -0,0 +1,21 @@
+#
+# Read in a line from STDIN, split it on whitespace,
+# put the result into an array 'words'
+#
+while read -a words
+do
+ #
+ # Iterate over the words backwards, and print them.
+ #
+ for ((i = ${#words[@]} - 1; i >= 0; i --));
+ do printf "%s" ${words[$i]}
+ #
+ # Print a newline after the final word; otherwise,
+ # print a space.
+ #
+ if (($i == 0))
+ then printf "\n"
+ else printf " "
+ fi
+ done
+done