I have a variable containing a multiline string.
I am going to interpolate this variable into another multiline echoed string, this echoed string has indentation.
Here's an example:
ip_status=`ip -o addr | awk 'BEGIN { printf "%-12s %-12s %-12s\n", "INTERFACE", "PROTOCOL", "ADDRESS"
printf "%-12s %-12s %-12s\n", "---------", "--------", "-------" }
{ printf "%-12s %-12s %-12s\n", $2, $3, $4 }'`
echo -e "
->
$ip_status
->
"
When running that, the first line of $ip_status is left justified against the ->
, however the subsequent lines are not justified against the ->
.
It's easier to see if you run that in your bash. This is the output:
->
INTERFACE PROTOCOL ADDRESS
--------- -------- -------
lo inet 127.0.0.1/8
lo inet6 ::1/128
eth0 inet 10.0.2.15/24
eth0 inet6 fe80::a00:27ff:fed3:76c/64
->
I want all the lines in the $ip_status
to be aligned with the ->
, not just the first line.