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

201
Views
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 answers
Answer question

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 Report

0

Maybe you just want this:

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

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 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!