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

416
Visualizações
Grep does not show color even when using --color=always

Grep usually shows highlighted text in red which is what I wanted but this time it doesn't seem to do that no matter what I do. I am doing this from a Docker container (nginx:1.19-alpine more specifically) and I installed Bash 5.1 using RUN apk add bash. Then I added a ~/.bashrc config file with this contents:

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

force_color_prompt=yes
color_prompt=yes

if [ "$color_prompt" = yes ]; then
    PS1='🐳 ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@server-nginx\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='🐳 ${debian_chroot:+($debian_chroot)}\u@server-nginx:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@server-nginx: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

The thing is that $ ls does show colored output. But when I try to pipe it through grep it still is black and white.

// Directories have colors!!
$ ls

// No color highlighting here
$ echo "baba" | grep --color=always ba

// No colors here either
$ ls | grep bin

The exact same setup on a different Docker image worked perfectly (php:7.4-fpm and node:14) so maybe there is something specific about the nginx:1.19-alpine image that it doesn't show colors for grep?

P.S. printf '%q\n' "$GREP_COLORS" "$GREP_COLOR" prints this output:

$ printf '%q\n' "$GREP_COLORS" "$GREP_COLOR"

ms=01\;33
''
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

After much digging around, I finally found the solution. The version of grep that came with this particular Docker image (nginx:1.19-alpine) was some kind of a "busybox version of grep". Anyway, upgrading grep did the trick:

// Inside of Dockerfile added this
RUN apk add --no-cache --upgrade grep

Now grep shows colored output. Phew! Hope this helps others who might run into this same issue.

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