Bash printf control characters
Johnny Rosenberg
gurus.knugum at gmail.com
Tue May 27 18:33:44 UTC 2014
2014-05-27 8:51 GMT+02:00 Patrick Asselman <iceblink at seti.nl>:
> In that case:
>
> printf "%-20s" söndag
>
> You may thank me for my help now :)
>
I might just do that… Thanks you for your help!
I didn't know that the - character was allowed. I wonder if that works with
printf in C too…
Johnny Rosenberg
>
>
> 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
>>
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20140527/bb89a893/attachment.html>
More information about the ubuntu-users
mailing list