diff options
| author | Abigail <abigail@abigail.be> | 2021-02-04 21:43:35 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-02-04 21:43:35 +0100 |
| commit | 539905267d623f18b736a6d375360cff83ce45e9 (patch) | |
| tree | c31f1924512ac2de6f6fbc2e97c638ffcfa5e7fb /challenge-098/abigail/bash | |
| parent | 2026690ecabb7764509b7845898cb4ba2298eb99 (diff) | |
| download | perlweeklychallenge-club-539905267d623f18b736a6d375360cff83ce45e9.tar.gz perlweeklychallenge-club-539905267d623f18b736a6d375360cff83ce45e9.tar.bz2 perlweeklychallenge-club-539905267d623f18b736a6d375360cff83ce45e9.zip | |
Bash solution for week 98, part 1
Diffstat (limited to 'challenge-098/abigail/bash')
| -rw-r--r-- | challenge-098/abigail/bash/ch-1.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/challenge-098/abigail/bash/ch-1.sh b/challenge-098/abigail/bash/ch-1.sh new file mode 100644 index 0000000000..ebd4353079 --- /dev/null +++ b/challenge-098/abigail/bash/ch-1.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# +# See ../README.md +# + +# +# Run as: bash ch-1.sh < input-file +# +# Each line of input consists of a filename and an amount +# of characters to read. +# + +# +# Create associative arrays +# +declare -A content +declare -A read + +function readN { + # + # Read arguments + # + filename=$1 + amount=$2 + + # + # First time? Then read in file. + # + if [ "${read[$filename]}" != "1" ] + then read[$filename]=1 + content[$filename]=$(<$filename) + fi + + # + # Leading $amount characters + # + r=${content[$filename]:0:$amount} + + # + # Remove $amount characters + # + content[$filename]=${content[$filename]:$amount} + + echo $r +} + + +# +# Read input, call readN +# +while read filename amount +do readN $filename $amount +done |
