help-bash
[Top][All Lists]
Advanced

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

Shifting a block of text


From: fatiparty
Subject: Shifting a block of text
Date: Mon, 13 Dec 2021 05:22:37 +0100 (CET)

Dec 8, 2021, 09:01 by chris@cfajohnson.com:

> 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
>
What is the reasoning for using both the width and the precision in setting up 
the variable pad?




reply via email to

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