help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shifting a block of text


From: Chris F.A. Johnson
Subject: Re: Shifting a block of text
Date: Wed, 8 Dec 2021 04:01:58 -0500 (EST)
User-agent: Alpine 2.22 (DEB 394 2020-01-19)

On Wed, 8 Dec 2021, Chris F.A. Johnson wrote:

On Wed, 8 Dec 2021, fatiparty--- via wrote:


Dec 8, 2021, 07:40 by fxmbsw7@gmail.com:

...
shifted-block "Phrase 1" "Phrase 2" "Phrase 3"
Print  phrases without any leading spaces (uses nc=0)

shifted-block 8 "Phrase 1" "Phrase 2" "Phrase 3" ...
Print phrases on separate lines with 8 leading spaces (uses nc=8)

shifted-block()
{
 case $1 in
   *[!0-9]*) ;;
   *) padding=$1
      shift ;;
 esac
 printf -v pad "%${padding}.${padding}s" ' '
 fmt=$pad%s'\n'
 printf "$fmt" "$@"
}

That doesn't allow for padding being already defined with a
numeric value.

It can be fixed, by adding 'local padding' at the top of the function
or

*[!0-9]*) padding=0;;

--
   Chris F.A. Johnson


reply via email to

[Prev in Thread] Current Thread [Next in Thread]