Created
August 22, 2023 10:16
-
-
Save zoolu-got-rhythm/86e0a927d2f22800d305984ab5a9e7ba to your computer and use it in GitHub Desktop.
cat here document not working for some reason (from line 31 to 34)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# this script has been tested on mac bash/terminal | |
# test valid input argument (directory path) | |
echo "ths is arg #: $#" | |
if [ $# -eq 0 ]; then | |
echo "no directory to search from supplied" | |
exit 1 | |
else | |
ls $1 &> /dev/null | |
if [ "$?" -ne "0" ]; then | |
echo "not a valid directory path" | |
exit 1 | |
fi | |
fi | |
show_line_number_and_starting_char_number=false | |
# check optional flags | |
while getopts ":n:h:" option; do | |
case $option in | |
n) | |
# code to execute when flag1 is provided | |
show_line_number_and_starting_char_number=true | |
;; | |
h) | |
# code to execute when flag2 is provided | |
cat << EOF | |
want my help | |
instructions for program | |
to go here | |
EOF | |
exit 0 | |
;; | |
*) | |
# code to execute when an unknown flag is provided | |
echo "Usage: $0 [-n] [-h] directory" | |
exit 1 | |
;; | |
esac | |
done | |
# if valid input directory path | |
dir=$1 | |
echo "searching for console.log's from root dir: $dir" | |
n=0 | |
for f in $(find $dir -type f -print); do | |
# console\s*(\.|\.\n|\n\.)\s*log is new console.log pattern to match for | |
# console.log was original pattern match/very primitive | |
console_logs_found_in_file=$(cat $f | grep -i -o -E 'console\s*(\.|\.\n|\n\.)\s*log' | wc -l | tr -d '[:blank:]') | |
if [ $console_logs_found_in_file -gt 0 ]; then | |
echo "$console_logs_found_in_file found in $f" | |
n=$((n + console_logs_found_in_file)) | |
fi | |
done | |
echo "total of $n console.log's found" | |
exit 0 # not sure if this needed really, default exit of program/script may be exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment