Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

181
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda