I have a rather large bash script which reads in a number of variables and then echoes them. I have no way to know beforehand the length of these variables and I do not want to shorten them or format them in any way - I just want them echoed in the same form they are read in.
To improve readability of my script's output I am echoing some lines to help the eye, something like this:
echo "--------------------------------"
echo "Here come some variables |"
echo " |"
echo "a = $a and b = $b"
echo " |"
echo "End of the script |"
echo "--------------------------------"
This will output:
--------------------------------
Here come some variables |
|
a = 1.23e-19 and b = hello
|
End of the script |
--------------------------------
What I want to achieve is for echo
(or some alternative solution) to recognize how many empty spaces it needs to insert after the variables are printed so it can align a vertical line |
with the rest of them, so that this output looks like this:
--------------------------------
Here come some variables |
|
a = 1.23e-19 and b = hello |
|
End of the script |
--------------------------------
It does not need to be an echo
only solution, but I would appreciate simplicity. Any ideas?