diff options
| author | Abigail <abigail@abigail.be> | 2021-02-12 17:24:05 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-03-04 18:57:26 +0100 |
| commit | 6d0ccb2c3e17a270f882d04098b3495d903a4b9d (patch) | |
| tree | 6ac33beb59461bf223ac6d46086cd33befaa2f49 /challenge-004/abigail | |
| parent | d48b695c863bfbf01418e8c5eef1db6f45b45e67 (diff) | |
| download | perlweeklychallenge-club-6d0ccb2c3e17a270f882d04098b3495d903a4b9d.tar.gz perlweeklychallenge-club-6d0ccb2c3e17a270f882d04098b3495d903a4b9d.tar.bz2 perlweeklychallenge-club-6d0ccb2c3e17a270f882d04098b3495d903a4b9d.zip | |
Bash solution for week 4, part 2
Diffstat (limited to 'challenge-004/abigail')
| -rw-r--r-- | challenge-004/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-004/abigail/bash/ch-2.sh | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-004/abigail/README.md b/challenge-004/abigail/README.md index 951045328c..be970d21a6 100644 --- a/challenge-004/abigail/README.md +++ b/challenge-004/abigail/README.md @@ -46,4 +46,5 @@ The sets of letters are read from standard input. ### Solutions * [GNU AWK](awk/ch-2.gawk) +* [Bash](bash/ch-2.sh) * [Perl](perl/ch-2.pl) diff --git a/challenge-004/abigail/bash/ch-2.sh b/challenge-004/abigail/bash/ch-2.sh new file mode 100644 index 0000000000..e9a2935272 --- /dev/null +++ b/challenge-004/abigail/bash/ch-2.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-2.sh -f FILE < input-file +# + +# +# Disable pathname expansion +# +set -f + +# +# Read the option +# +while getopts "f:" name +do if [ "$name" = "f" ] + then file=$OPTARG + fi +done + + +while read letters +do letters=${letters^^[a-z]} # Upper case the letters + while read word # Read word from file + do copy=${word^^[a-z]} # Make a copy, and upper case it + for ((i = 0; i < ${#letters}; i ++)) # Iterate over letters + do copy=${copy/${letters:$i:1}/} # Remove letter from copy + done + if [ ${#copy} -eq 0 ] # If we end up with an empty + then echo $word # string, we have a winner + fi + done < $file # We're reading from the $file +done |
