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

208
Vistas
bash while string is not empty

I'm trying to set up a script that parses a string.

My loop is currently

while [ -n "$RAW" ]; do
    // do some processing here
    RAW=$(echo $RAW| sed -r 's/^.{15}//')
done

However, the script never seems to end

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

It is not ending because the sed expression is not correct. It expects minimum 15 characters and does not work for anything less than 15 chars. Try this:

RAW=$(echo $RAW| sed -r 's/^.{0,15}//')
over 4 years ago · Santiago Trujillo Denunciar

0

Maybe you just want this:

#!/bin/bash
RAW=012345678901234567890
.
.
.
RAW=${RAW:15}
echo $RAW
567890
over 4 years ago · Santiago Trujillo Denunciar

0

It might not end because of the logic inside your while loop.

You're doing to overwrite variable RAW:

RAW=$(echo $RAW| sed -r 's/^.{15}//')

Which means match and replace first 15 characters in original variable by empty string. What is there are only 10 characters left. In that sed won't match (and replace) and your varialbe RAW will remain at that value.

You probably want upto 15 characters from start to be replaced and if that's the case this is what you will need:

RAW=$(echo $RAW | sed -r 's/^.{1,15}//')
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