diff options
author | braxtonhall | 2022-10-25 06:36:28 +0000 |
---|---|---|
committer | braxtonhall | 2022-10-25 06:36:28 +0000 |
commit | ccfa3ef5a9d811a003d6fa9701b9f1e27f44ce33 (patch) | |
tree | d7436c329cc15ac1125c7cd844086f3e894a93fb | |
parent | 8b4b5107bc40aa8e4d5dfece7b582494c7cde068 (diff) |
Make wc a little bit safer
-rw-r--r-- | entries/braxtonhall/wc/fib.sh | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/entries/braxtonhall/wc/fib.sh b/entries/braxtonhall/wc/fib.sh index c909617..fc419b3 100644 --- a/entries/braxtonhall/wc/fib.sh +++ b/entries/braxtonhall/wc/fib.sh @@ -1,18 +1,22 @@ #!/bin/bash -rec () { - shopt -s nullglob dotglob +function rec () { if [ $2 == "0" ]; then : elif [ $2 == "1" ]; then - echo "🥵" > "$1/$2.fib" + [ -f "$1/$2.fib" ] || echo "🥵" > "$1/$2.fib" else - mkdir "$1/$2" + [ -d "$1/$2" ] || mkdir "$1/$2" rec "$1/$2" $(($2 - 1)) rec "$1/$2" $(($2 - 2)) fi } -rec $(pwd) $1 -find $(pwd)/$1 -type f | wc -l +if [[ $1 =~ ^[0-9]+$ ]]; then + rec $(pwd) $1 + find $(pwd)/$1 -type f | wc -l +else + echo "Please provide a natural number!" + exit 1 +fi |