Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda