Skip to content

Instantly share code, notes, and snippets.

@honzahommer
Last active January 28, 2019 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save honzahommer/d8a2461113936ee08872b7e7765f4342 to your computer and use it in GitHub Desktop.
Save honzahommer/d8a2461113936ee08872b7e7765f4342 to your computer and use it in GitHub Desktop.
ismac.sh
#!/usr/bin/env bash
_ver=$(echo $BASH_VERSION | awk -F. '{ printf "%i%i", $1, $2 }')
ismac() {
if [[ $# -eq 0 ]] ; then
return 1
fi
if [[ $# -gt 1 ]] ; then
local this="${FUNCNAME[0]}"
for i in "$@"; do
$this $i || return 1
done
fi
local mac=$1
if [[ $_ver -gt 31 ]]; then
[[ "$mac" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]] && return 0
else
[[ "$mac" =~ "^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$" ]] && return 0
fi
return 1
}
if [[ $# -ne 0 ]] ; then
ismac $@
exit $?
fi
#!/usr/bin/env bash
this=$(basename $0)
func=${this%".test.sh"}
file="$(dirname $0)/$func.sh"
if [ ! -f "$file" ]; then
echo "$file: File not found"
exit 1
fi
\. "$file"
if [[ $(type -t $func) != function ]]; then
echo "$func: Function not found"
exit 0
fi
while read -r test; do
$func $test || exit 1
done << EOF
aa:aa:aa:aa:aa:aa
FF:FF:FF:FF:FF:FF
EOF
while read -r test; do
$func $test && exit 1
done << EOF
aa:aa:aa:aa:aa:ax
FF:FF:FF:FF:FF:Fg
aa:aa:aa:aa:aaaa
FF:FF:FF:FFFF:FF
EOF
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment