Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
bash case statement quoting behaves as documented, but please explain

c.f. the case example here
Specifically:

$: g=a*[b]; case $g in $g) echo 'unquoted pattern' ;; "$g") echo 'quoted pattern' ;; esac
quoted pattern

A simple string behaves exactly as expected -

$: g=a; case $g in $g) echo 'unquoted pattern' ;; "$g") echo 'quoted pattern' ;; esac
unquoted pattern

I made sure there was no matching file to glob, no shopt options muddying the water, and tested the value explicitly:

$: echo @$g@ "@$g@" $g "$g"
@a*[b]@ @a*[b]@ a*[b] a*[b]
$: [[ $g == "$g" ]] && echo ok || echo no
ok

So why does it, in this case, choose the second option?
Shouldn't both evaluate to the same results?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The case statement uses pattern matching, not string equality, to compare the word to each pattern.

The pattern a*[b] matches any string starting with an a, with zero or more characters followed by a single b. It does not match the string a*[b], because that string ends with a ], not a b.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!