Score:0

Introducing stars underneath phrase

jp flag

I am using this bash function to print a phrase with stars below it.
Am looking at how the implementation can be simplified?

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

outline "Stack Exchange"
outline "   Stack Exchange"

results in

Stack Exchange
**************
   Stack Exchange
   **************
elmclose avatar
cn flag
It might be easier to use underline or other formatting tools to make your text stand out (if that is what you intend to do). You can check out this link for comprehensive guide: https://misc.flogisoft.com/bash/tip_colors_and_formatting For example to underline your phrase try this: echo -e "\e[4mStack Exchange\e[0m"
jp flag
I find the line too thin for me. Furthermore, the leading spaces also get underlined.
elmclose avatar
cn flag
try echo -e " \e[4mStack Exchange\e[0m"
stumblebee avatar
mx flag
A similar question was asked on [stackoverflow](https://stackoverflow.com/questions/70149677/underline-with-stars-from-first-non-space-character) Good luck on your school project!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.