I have created this Function , which generate below output on terminal , but this function seems complex, So I posted here for any improvement or for same alternate solution.#!/bin/bashfunction box_out() {        input_char=$(echo $@ | wc -c)        line=$(for i in `seq 0 $input_char`; do printf -; done)        # tput This should be the best option. what tput does is it will read the terminal info and render the correctly escaped ANSI code for you. code like \033[31m will break the readline library in some of the terminals.        tput bold        line=$(tput setaf 3)${line}        space=${line//-/ }        echo  ${line}        printf '|' ; echo -n $space ; printf %s\n '|';        printf '| ' ;tput setaf 4; echo -n $@; tput setaf 3 ; printf %s\n ' |';        printf '|' ; echo -n $space ; printf %s\n '|';        echo  ${line}        tput sgr 0}box_out $@
bash script , echo output in box
printf;tput;bash script
As your shebang and syntax indicates unportable bash, I prefer it this way:function box_out(){  local s=$*  tput setaf 3  echo  -${s//?/-}-| ${s//?/ } || $(tput setaf 4)$s$(tput setaf 3) || ${s//?/ } | -${s//?/-}-  tput sgr 0}Of course, you can optimize it if you wish.Update as requested in comment, to handle multiline text too.function box_out(){  local s=($@) b w  for l in ${s[@]}; do    ((w<${#l})) && { b=$l; w=${#l}; }  done  tput setaf 3  echo  -${b//?/-}-| ${b//?/ } |  for l in ${s[@]}; do    printf '| %s%*s%s |\n' $(tput setaf 4) -$w $l $(tput setaf 3)  done  echo | ${b//?/ } | -${b//?/-}-  tput sgr 0}Call it with multiple parameters, like box_out 'first line' 'more line' 'even more line'.