Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash while string is not empty

Tags:

string

linux

bash

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

like image 501
dreadiscool Avatar asked Mar 21 '26 20:03

dreadiscool


2 Answers

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}//')
like image 160
perreal Avatar answered Mar 24 '26 12:03

perreal


Maybe you just want this:

#!/bin/bash
RAW=012345678901234567890
.
.
.
RAW=${RAW:15}
echo $RAW
567890
like image 31
Mark Setchell Avatar answered Mar 24 '26 11:03

Mark Setchell