Why is the output of these two different? I want the spaces to be preserved.
#!/bin/bash
x="foo"
printf "%-12s *" $x
echo " "
y=$(printf "%-12s" $x)
echo $y "*"
Running it gives
foo *
foo *
I want the second line to look like the first.