我正在使用这个 bash 函数打印一个下面带有星号的短语。
想知道如何简化实现吗?
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//?/*}"
}
调用以下命令
outline "Stack Exchange"
outline " Stack Exchange"
结果是
Stack Exchange
**************
Stack Exchange
**************