aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-03 19:54:29 +0200
committerAbigail <abigail@abigail.be>2021-05-03 19:56:44 +0200
commit01863a959124994447b60f267c0e6c516f3380d1 (patch)
treed398e8a684edf59cb6694218c4e1b83e73eeb33c
parentfb6114ea6265a0a8242fb07246026fe0023329d6 (diff)
downloadperlweeklychallenge-club-01863a959124994447b60f267c0e6c516f3380d1.tar.gz
perlweeklychallenge-club-01863a959124994447b60f267c0e6c516f3380d1.tar.bz2
perlweeklychallenge-club-01863a959124994447b60f267c0e6c516f3380d1.zip
Bash solution for week 111, part 2
-rw-r--r--challenge-111/abigail/README.md1
-rw-r--r--challenge-111/abigail/bash/ch-2.sh30
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md
index 87191419b0..1b8e0cd4dd 100644
--- a/challenge-111/abigail/README.md
+++ b/challenge-111/abigail/README.md
@@ -51,6 +51,7 @@ to standard output. In case of ties, we print the first one found.
### Solutions
* [GNU AWK](awk/ch-2.gawk)
+* [Bash](bash/ch-2.sh)
* [C](c/ch-2.c)
* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
diff --git a/challenge-111/abigail/bash/ch-2.sh b/challenge-111/abigail/bash/ch-2.sh
new file mode 100644
index 0000000000..7add8bc05f
--- /dev/null
+++ b/challenge-111/abigail/bash/ch-2.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+#
+# See ../README.md
+#
+
+#
+# Run as: bash ch-2.sh < input-file
+#
+
+
+set -f
+shopt -s extglob
+
+pat1="*(a)*(b)*(c)*(d)*(e)*(f)*(g)*(h)*(i)*(j)*(k)*(l)*(m)"
+pat2="*(n)*(o)*(p)*(q)*(r)*(s)*(t)*(u)*(v)*(w)*(x)*(y)*(z)"
+
+longest=""
+
+while read line
+do lower=${line,,} # Lower case input
+ left=${lower/#$pat1$pat2/} # Remove pattern
+ # Test whether nothing left,
+ # and string larger longest found
+ if [ "X$left" == "X" -a ${#line} -gt ${#longest} ]
+ then longest=$line
+ fi
+done
+
+echo $longest