A Bash script must exit with status 0 only when the variable MAC holds a valid MAC address in the canonical form 01:23:45:67:89:ab (six hexadecimal octets separated by colons). Which of the following one-line conditionals correctly performs this check without spawning external commands and leaves the exit status unchanged when the value does not match?
The [[ … ]] compound command is parsed by Bash itself, so it can use the =~ binary operator to apply a POSIX-extended regular expression to the string on its left side. The pattern ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ anchors the match at the start (^) and end ($) of the string and requires exactly six pairs of hexadecimal digits separated by colons. When the match succeeds, [[ … ]] returns 0; when it fails, it returns 1, so the script continues. All other choices either use the single-bracket test (which does not understand =~), quote the right-hand side so that Bash treats it as a literal string instead of a regular expression or rely on an unportable operator. Because no external utilities are invoked, the solution is efficient and safe on systems with a minimal userland.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What does the =~ operator do in Bash?
Open an interactive chat with Bash
Why does single-bracket `[ ... ]` not support =~ in Bash?
Open an interactive chat with Bash
What does the regular expression ^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$ mean?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
Automation, Orchestration, and Scripting
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .