Skip to content

Instantly share code, notes, and snippets.

@fuji246
Last active March 19, 2020 20:47
Show Gist options
  • Save fuji246/64658305cd3dc1a481158734ddf5c0db to your computer and use it in GitHub Desktop.
Save fuji246/64658305cd3dc1a481158734ddf5c0db to your computer and use it in GitHub Desktop.
shell script recipe
  1. loop file with pattern
lines=$(find "$logdir" -name '*.log' -print)

while read line
do
    echo "processing \"$line\""
done <<< "$(echo -e "$lines")"
  1. get abspath, dirpath and basename
abspath="$(cd "$(dirname "$file")" && pwd)/$(basename "$file")"
dirpath=$(dirname "$abspath")
basename=$(basename "$abspath" ".log")
  1. check substring
string='My long string'
if [[ $string == *"My long"* ]]; then
  echo "It's there!"
fi
  1. bold
bold=$(tput bold)
normal=$(tput sgr0)

echo "${bold}This is bold {normal} and back to normal"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment