This question already has an answer here:
- I just assigned a variable, but echo $variable shows something else 6 answers
For string matching purposes I need to define a bash variable with leading spaces. I need to define this starting from an integer, like:
jj=5
printf seems to me a good idea, so if I want to fill spaces up to 6 character:
jpat=`printf " %6i" $jj`
but unluckly when I am trying to recall the variable:
echo $jpat
the leading whitespaces are removed and I only get the $jj
integer as it was.
Any solution to keep such spaces?
(This is equivalent to this: v=' val'; echo $v$v
. Why aren't there leading and multiple spaces in output?)