Bash/Printf: Unterschied zwischen den Versionen
Aus SchnallIchNet
< Bash
Cbs (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „==repeated output== if you want to format output e.g. by spaces do printf "%10s" " " this will produce a 10 bytes long string of ' ' (spaces).<br/> if you want t…“) |
Cbs (Diskussion | Beiträge) K (hat „Printf“ nach „Bash/Printf“ verschoben) |
(kein Unterschied)
|
Version vom 24. April 2013, 06:20 Uhr
repeated output
if you want to format output e.g. by spaces do
printf "%10s" " "
this will produce a 10 bytes long string of ' ' (spaces).
if you want to have anything else than spaces use tr
printf "%10s" " " | tr ' ' '#' ##########
this is because non-given strings are interpretes as NULL-string
so the following does NOT work:
printf "%10s" "#" #
printf expects a 10-byte long string because of the %10s format string.
because it only gets 1 byte. it prints out 9 bytes spaces and only ONE '#'
this is the reason you will have to use tr