Article 5SEZP Stars under headin starting at first non-space character

Stars under headin starting at first non-space character

by
Faki
from LinuxQuestions.org on (#5SEZP)
I am using this bash function to print a phrase with stars below it.
Am looking at how the implementation can be simplified?

Code:outline ()
{
titl="$1"
n="${#titl}"

# extract leading spaces
[[ $titl =~ ^(\ )* ]]; spaces="${BASH_REMATCH[0]}"

# remove leading spaces from titl
titl="${titl/#$spaces/}"

echo "$spaces$titl"
echo "$spaces${titl//?/*}"
}Invoking the following commands

Code:outline "Linux Questions"
outline " Linux Questions"results in

Code:Linux Questions
***************
Linux Questions
***************latest?d=yIl2AUoC8zA latest?i=tNwwNBlhVOw:x93sEls6cqE:F7zBnMy latest?i=tNwwNBlhVOw:x93sEls6cqE:V_sGLiP latest?d=qj6IDK7rITs latest?i=tNwwNBlhVOw:x93sEls6cqE:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments