Last active
January 28, 2019 21:36
-
-
Save honzahommer/d8a2461113936ee08872b7e7765f4342 to your computer and use it in GitHub Desktop.
ismac.sh
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
#!/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 |
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
#!/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