Skip to content

Instantly share code, notes, and snippets.

@angelbladex
Last active April 1, 2025 19:02
Show Gist options
  • Select an option

  • Save angelbladex/03d96e69fb249a00ce48 to your computer and use it in GitHub Desktop.

Select an option

Save angelbladex/03d96e69fb249a00ce48 to your computer and use it in GitHub Desktop.
Validate mac address
#!/bin/bash
if [[ ! -n "$1" ]]; then
echo "Error: Missing Mac Address"
exit 1
fi
if [[ "$1" =~ ^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$ ]]; then
echo "Valid MAC Address ($1)"
exit 0
else
echo "Error: Invalid MAC Address: $1"
echo "Format accepteds:"
echo " XX:XX:XX:XX:XX:XX"
echo " XX-XX-XX-XX-XX-XX"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment