Colorize a pattern in the given input using a neat regex and colorization hack in grep
($ matching all lines but not being able to be highlighted).
color (){# Color highlight the pattern in the incoming stream, writing to stdout# This effectively matches our PATTERN andy any "$" (line end)# But only our PATTERN can be highlighted, line end characters aren't actually there to be highlightedlocalPATTERN=$1if[ -z "$1"];thenecho"Usage: color <pattern>"echo"Description: Greps input with --color=always -E 'PATTERN|\$' "echo"Example: echo \"hello world\" | color \"world\""return1fi grep --color=always "$PATTERN\|\$"}
DNS is something so fundamental to most of our systems functioning that it’s often overlooked in initial troubleshooting,
it’s also incredibly hard to troubleshoot if it’s only intermittently failing.
Many of my scripts work with temporary files, usually relative to the scripts directory1,
while at the same time using set -e to exit as soon as something fails.
In this scenario the script leaves behind these temporary files by default, which is not desirable.
We can however do a proper cleanup using the trap concept.
Often times we need the current date (and time) when scripting inside bash or other shells.
For example when creating a backup file or writing to a log.
Often times when writing scripts I want to reference files in the same directory,
but keep the script portable in case it is part of a git repository being checked out somewhere else
or just the folder getting moved.
Copy & paste from untrusted sources on the internet into the terminal is a really bad idea!
Early in my career I did it too and still often see others doing it.