I'm working in Bash. I'm trying to get a particular variable to always be the same length, 16 characters long, regardless what is passed into it.I triedt=33455until [[ ${#t} == 16 ]]; dot=${t} donebut it seems to run forever. It would seem that the spaces aren't treated as characters.  Is there any way to get the variable to always be 16 characters long?EDIT: I forgot to include an important bit of context. I updated the code to reflect.  None of the variables that will be put in are more than 6 digits initially. When I do the above, it runs infinitely.
Ensure a variable has a certain # of spaces
bash;shell script
As for the issue at hand I guess Dickey is on the track.As for an alternative, perhaps use something like:t=$(printf %-16.16s $t)If t is always shorter then 16, which you have to be completely sure of, you could do:t=$(printf %-16s $t)Note that it will crash on non-ASCII characters. For example, test:$ x=123$ x=$(printf %-16.16s $x)$ printf |%s|\n|1234567890123456|789012\n $x|123             ||1234567890123456|789012$ x=12345678901234567890123456$ x=$(printf %-16.16s $x)$ printf |%s|\n|1234567890123456|789012\n $x|1234567890123456||1234567890123456|789012$ x=sadasdsasd$ x=$(printf %-16.16s $x)$ printf |%s|\n|1234567890123456|789012\n $x|sadasdsasd|                                     <<<--- ups!|1234567890123456|789012(Or the more fancy:printf \e[41m%s\e[0m\n\e[41m1234567890123456\e[0m789\n $x)