Bash printf control characters
Patrick Asselman
iceblink at seti.nl
Tue May 27 06:51:49 UTC 2014
In that case:
printf "%-20s" söndag
You may thank me for my help now :)
Best regards,
Patrick Asselman
On 2014-05-26 21:35, Johnny Rosenberg wrote:
> 2014-05-26 12:34 GMT+02:00 Patrick Asselman <iceblink at seti.nl>:
>
>> You could tell printf to use a certain width for your %A variable.
>> The variable is printed aligned to the right of its assigned space,
>> and the space in front is filled with space characters.
>>
>> example:
>> printf "%20s" söndag
>
> Doesn't work. The spaces end up at the beginning of the string, not
> at the end of it.
>
> Johnny Rosenberg
>
>
>> (haven't tested it, but should work)
>>
>> Patrick
>>
>> On 2014-05-24 19:14, Johnny Rosenberg wrote:
>>
>>> I wrote this bash function, just for no particular reason, learning
>>> I guess:
>>>
>>> function lvdati () {
>>> while [[ 1 ]]; do
>>> printf 'r%(%F %T (%A))T' -1
>>> sleep 0.1
>>> done
>>> }
>>>
>>> It displays the current date and time in the terminal (use Ctrl+c
>>> to
>>> terminate it) in a certain format. On my machine, it looks like
>>> this,
>>> for instance:
>>> 2014-05-24 18:58:50 (lördag)
>>>
>>> What I don't want to happen is this:
>>> 2014-05-22 23:59:59 (torsdag)
>>> Then a second later:
>>> 2014-05-23 00:00:00 (fredag))
>>>
>>> Since ”fredag” (friday) is one character shorter than ”torsdag”
>>> (thursday), the last character of the torsdag line will still
>>> remain,
>>> won't it?
>>> So I need something at the end of the string that works like Ctrl+k
>>> in the terminal (erase everything on the right side of the cursor),
>>> but how do I implement it?
>>>
>>> Let's say that Ctrl+k='k' (it isn't, but just imagine it…), then I
>>> would try:
>>> function lvdati () {
>>> while [[ 1 ]]; do
>>> printf 'r%(%F %T (%A))Tk' -1
>>>
>>> sleep 0.1
>>> done
>>> }
>>>
>>> Suggestions (except adding one or more spaces to the string)?
>>>
>>> Johnny Rosenberg
>>
>> --
>> ubuntu-users mailing list
>> ubuntu-users at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users [1]
>
>
>
> Links:
> ------
> [1] https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
More information about the ubuntu-users
mailing list