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
***************
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
***************