PodcastsNieuwsHacker Public Radio

Hacker Public Radio

Hacker Public Radio
Hacker Public Radio
Nieuwste aflevering

287 afleveringen

  • Hacker Public Radio

    HPR4667: UNIX Curio #9 - printf

    23-06-2026
    This show has been flagged as Clean by the host.

    This series is dedicated to exploring little-known—and occasionally useful—trinkets lurking in the dusty corners of UNIX-like operating systems.


    The
    echo
    command is very useful—it prints the arguments given to it, followed by a newline character. (The newline is sometimes also called a linefeed character depending on who is writing or speaking, and has the ASCII decimal value 10.) It has many uses, either in a script or interactively on the command line. The
    echo
    utility is used to display text, the value of a variable, or the result of a pathname expansion. It can also feed text to another command in a pipeline.



    As useful as
    echo
    is, it should come as no surprise that it
    first appeared early on in Bell Laboratories' Second Edition UNIX


    1
    in 1972. This
    initial version accepted no options


    2
    —although the manual page doesn't explicitly say output is followed by a newline character, the description of writing "as a line" seems to imply it. In
    Seventh Edition UNIX, the manual page


    3
    makes that clear, and also features the addition of the
    -n
    option, which causes
    echo
    to print the arguments
    without
    a trailing newline character.
    Eighth Edition UNIX's




    echo




    4
    gained the
    -e
    option, which allows certain escape codes from the C programming language to be used.



    These variations caused differences in behavior between different versions of
    echo
    . Will running
    echo -n something
    on your system output the text "something" without a newline, or "-n something" followed by a newline? Things get even trickier when the command arguments include parameter or pathname expansions. If there are files named "-n" and "something" in the current directory, what does
    echo *
    output? Like the previous question, that depends on whether or not your version of
    echo
    treats
    -n
    as an option. You can't get around this ambiguity by quoting or escaping the "*", because that just causes
    echo
    to print a literal asterisk.





    Example using GNU utilities on Debian 12; both the "echo" utility and the "echo" builtin of bash recognize "-n" as an option.




    $ ls -1
    -n
    something
    $ echo *
    something$ #Shell prompt is on the same line because "-n" was treated as an option to echo
    $ echo "*"
    *



    The solution was to create a new utility, which is the first UNIX Curio for today:
    printf
    . This command allows a user to print text similar to the way the identically-named function works in the C programming language. You
    run




    printf




    5
    followed by a format string, followed by zero or more arguments. No newline characters are printed unless specifically indicated by the format string or the arguments.



    To use
    printf
    to print "something" without a newline, that would just be
    printf something
    . This demonstrates that you don't need any arguments—in this example, the format string is just a set of regular characters to be displayed. If you wanted a newline character at the end,
    printf "something\n"
    would give you that. (In this case, the format string needs to be quoted so the "\n" isn't interpreted by the shell.) In addition to "\n" for a newline, you can also use "\a" for an alert (rings the terminal bell), "\b" for a backspace, "\f" for a formfeed, "\r" for a carriage return, "\t" for a horizontal tab, "\v" for a vertical tab, and "\\" to get a literal backslash. In addition to these special characters, any arbitrary byte can be included using a backslash followed by one to three octal digits; however, it might be difficult to predict what will be output because it can differ based on the character set the terminal is using. It is safer and more portable to stick to the pre-defined characters if possible.



    The
    real
    magic of the
    printf
    utility comes from using "conversion specifications" in the format string. Probably the simplest of these to explain is the "%s" conversion specification—it represents a string of any length. The command
    printf "Hi, %s, how are you?\n"
    followed by a list of names would print the greeting for each name, putting it in the place occupied by the "%s".



    $ printf "Hi, %s, how are you?\n" Alice Bob Carol
    Hi, Alice, how are you?
    Hi, Bob, how are you?
    Hi, Carol, how are you?



    The format string is reused as many times as needed to consume all of the arguments. Take, for example, the command
    printf "Hi, %s, have you met %s?\n"
    . If this is run with two name arguments, it would print the sentence on one line, using both names. If run with four name arguments, it would print the sentence twice, once with the first two names and again with the second two names. If you only gave it three names, the last "%s" conversion specification would be replaced with a null string.



    $ printf "Hi, %s, have you met %s?\n" Alice Bob
    Hi, Alice, have you met Bob?
    $ printf "Hi, %s, have you met %s?\n" Alice Bob Carol David
    Hi, Alice, have you met Bob?
    Hi, Carol, have you met David?
    $ printf "Hi, %s, have you met %s?\n" Alice Bob Carol
    Hi, Alice, have you met Bob?
    Hi, Carol, have you met ?



    Three other items can also be given in each conversion specification: flags, the field width, and the precision. The exact meanings of these depend on which type of conversion specifier character you are using. For "%s", using a "-" as the flag causes the text to be left-justified instead of the default right-justified, a field width causes the printed field to be at least as long as the number given, and a precision limits the number of bytes written from the string to the number given.



    $ #Example of %s with a precision value
    $ printf "Hi, %.3s, how are you?\n" Alice Bob Carol
    Hi, Ali, how are you?
    Hi, Bob, how are you?
    Hi, Car, how are you?
    $ #Example of %s with a field width
    $ printf "Hi, %8s, how are you?\n" Alice Bob Carol
    Hi, Alice, how are you?
    Hi, Bob, how are you?
    Hi, Carol, how are you?
    $ #Example of %s with a left-justify flag and a field width
    $ printf "Hi, %-8s, how are you?\n" Alice Bob Carol
    Hi, Alice , how are you?
    Hi, Bob , how are you?
    Hi, Carol , how are you?
    $ #Example of %s with a left-justify flag, a field width, and a precision
    $ printf "Hi, %-8.3s, how are you?\n" Alice Bob Carol
    Hi, Ali , how are you?
    Hi, Bob , how are you?
    Hi, Car , how are you?



    While "%s" is probably the most commonly-used conversion specification, others are available. A whole set of them are dedicated to printing integer values as a signed decimal, an unsigned decimal, an unsigned octal, or an unsigned hexadecimal number. These also can take flags, a field width, and a precision. I think the details and nuances of all this are too complex to clearly explain here, so I will just refer you to the
    POSIX "file format notation" specification


    6
    .



    Be aware that unlike the
    printf
    function in the C programming language, the
    printf
    utility is
    not
    obligated to accept conversion specifications for floating-point numbers. While some implementations might support this, scripts intended to be portable should limit themselves to the restricted set required by the POSIX standard (%d, %i, %o, %u, %x, %X, %c, and %s, plus %b and %% described below).



    Two more conversion specifications are worth mentioning. The first is
    only
    required by the standard for the
    printf
    utility, not the C function, and is "%b". This is the same as "%s", except that certain backslash escape sequences in the argument will be treated specially. This includes all the ones described above
    except
    for the one using octal digits to represent a byte. In an argument, this is instead represented by "\0" followed by one to three octal digits. An additional backslash escape sequence accepted is "\c"—this does not print anything itself, but causes
    printf
    to immediately halt output.



    The final conversion specification is "%%", which just outputs a literal "%". You can't use a bare "%" in the format string, because
    printf
    expects that to introduce a conversion specification. Be careful not to be tripped up by this when trying to print some value as a percentage.





    Example assuming that the hypothetical "/dev/batterycharge" file on your laptop outputs the battery charge level (42% in this case). As you can see, in some cases an error message might be displayed, but in others it might just behave in a way you didn't intend without complaining. GNU's "printf" utility and the "printf" builtin of bash both support "%e" as a conversion specification as an extension to POSIX.




    $ cat /dev/batterycharge
    42
    $ #Wrong
    $ printf "Your laptop's charge level is $(cat /dev/batterycharge)%.\n"
    bash: printf: `\': invalid format character
    Your laptop's charge level is 42$ #Shell prompt appears here from the error
    $ #Right
    $ printf "Your laptop's charge level is $(cat /dev/batterycharge)%%.\n"
    Your laptop's charge level is 42%.
    $ #Next one treats %e as the specifier, with the space and "l" as flags
    $ printf "Your laptop has $(cat /dev/batterycharge)% level of charge.\n"
    Your laptop has 42 0.000000e+00vel of charge.
    $ #Because no arguments were given, "0" was used for the value to convert



    Let's go back to the situation I was describing with
    echo
    —we have files named "-n" and "something" in the current directory and want to print all their names, separated by spaces. We could do that with
    printf "%s " *
    , which would not treat the "-n" as an option. However, the output might look a little weird because there wouldn't be a newline character at the end. We could insert a newline by using "%b" instead of "%s" and following the asterisk with a "\n\c" as the second argument. The "\c" is there to prevent the final space in the format string from being printed after the newline.



    $ ls -1
    -n
    something
    $ printf "%s " *
    -n something $ #No newline was printed here
    $ printf "%b " * "\n"
    -n something
    $ #There's a newline, but also a spurious space before the shell prompt
    $ printf "%b " * "\n\c"
    -n something
    $ #No space before the shell prompt this time



    Using the "%b" conversion specification can therefore solve one problem, but it also introduces another. Arguments which include a backslash can be interpreted as escape sequences, and many systems are fine with allowing backslashes in filenames. In cases where you're just using the
    printf
    utility to
    display
    text, it's usually not a big deal if the output looks a little wonky. Where you really need to be careful is when the text is being piped to another program, as control characters and other oddities might cause unexpected results, and can potentially create security problems if processed by a script or utility running as a privileged user.



    $ #GNU "ls" displays filenames containing a backslash in single quotes
    $ ls -1
    apple
    banana
    '\cherry'
    durian
    $ printf "%b " * "\n\c"
    apple banana $ #"\c" in "\cherry" stops output immediately



    The
    printf
    utility
    looks to have shown up first in 1986's Ninth Edition UNIX


    7
    , though the
    earliest manual page I could find


    8
    is from the Tenth Edition. Its first appearance in BSD
    seems to be from 1990 in the 4.3 Reno release


    9
    . Two years later, it was added to Issue 4 of The Open Group's CAE Specification. From what I can tell, it did not seem to be in AT&T's System III—presumably the
    printf
    utility did make it into System V at some point but I found it difficult to track this down.



    While
    echo
    is still suitable for use where you know for certain that you want a newline character printed at the end and none of the arguments will start with a hyphen, consider using the
    printf
    utility instead for displaying text. It offers more flexibility and features than you are guaranteed to get with
    echo
    , although it does require a bit of forethought in constructing a proper format string and arguments. That is not necessarily a bad thing, because a script's author
    should
    be thinking about what might happen if it is called with "strange" text or filenames.



    This episode also provides a good case for being careful when naming files—many filesystems will allow you to use hyphens, control characters, quotation marks, and potentially any character other than a slash or a null byte in a filename. As we've seen, some of these characters can create problems for standard utilities. While it can feel limiting, especially for people not using English, the safest filenames to use on a UNIX-like system consist only of characters in the
    "portable filename character set" as defined by POSIX


    10
    and where the first character is
    not
    a hyphen. This set includes the lowercase and uppercase letters "a" through "z", the numerals "0" through "9", and the period, underscore, and hyphen. Notably, it does
    not
    include the space character.



    That leads me to another UNIX Curio that I only just now discovered while researching this episode. This is
    the




    pathchk




    utility


    11
    . It can be run with one or more strings as arguments, checks each one against a set of rules for pathnames, and outputs an error message for each problem found. By default, it checks against the following limits on the system where it's being run: maximum number of bytes in the full path, maximum number of bytes in any component of the path, all byte sequences must be valid in the given directory, and the user running the program must have access to all directories referenced. If run with the
    -p
    option, instead of those limits, it checks against POSIX limits: a maximum of 256 bytes in the full path, a maximum of 14 bytes in each component of the path, and each component must only include characters from the portable set. The
    -P
    option adds warnings if any component starts with a "-" or if the pathname is completely empty. While the exit status will tell you if the checks succeeded or not, I don't feel like the
    pathchk
    utility is well suited to be used in an automated fashion, as the exact wording of its output is not specified and checks cannot be selected individually. However, it can be used interactively to validate pathnames you aren't sure about. See the linked specification for full details.



    References:







    A Research UNIX Reader: Combined Tables of Contents
    https://archive.org/details/a_research_unix_reader/page/n99/mode/1up





    A Research UNIX Reader: Second Edition UNIX echo manual page
    (although this page has "v1" typed at the top, the date and the tables of contents indicate it first appeared in v2, a.k.a. Second Edition) https://archive.org/details/a_research_unix_reader/page/n22/mode/1up





    Seventh Edition UNIX echo manual page
    https://man.cat-v.org/unix_7th/1/echo





    Eighth Edition UNIX echo manual page
    https://man.cat-v.org/unix_8th/1/echo





    Printf specification
    https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html





    File Format Notation specification
    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap05.html





    A Research UNIX Reader: Ninth Edition Table of Contents
    https://archive.org/details/a_research_unix_reader/page/n95/mode/1up





    Tenth Edition UNIX echo/printf manual page
    https://man.cat-v.org/unix_10th/1/echo





    4.3BSD Reno printf manual page
    https://man.freebsd.org/cgi/man.cgi?query=printf&sektion=1&manpath=4.3BSD+Reno





    Definitions: Portable Filename Character Set
    https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282





    Pathchk specification
    https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pathchk.html







    Provide feedback on this episode.
  • Hacker Public Radio

    HPR4666: How I got into tech

    22-06-2026
    This show has been flagged as Clean by the host.

    I started out with Basic on the TI-99/4A in 1984. The bare machine could not be programmed by the user in machine code. In 1985 I bought a ZX Spectrum, that gave me total control over the machine.

    I wrote two FORTH systems on the ZX-Spectrum.

    In 1988 I got my first 8088 PC, also programming it in FORTH.

    In 1992 I got an 80386 PC and I ran Linux on it. MCC Interim Release from v. This was the first Linux distro.

    I have been using Linux ever since.

    From then on I obtained newer PCs, such as a Pentium in 1995, a Pentium-2 in 1998, a Pentium-4 in 2003 and a Core-2 Duo in 2006.

    I used several Linux distributions: but I always return to Debian.

    Links:

    https://github.com/ForthHub/F83 F83.COM is the ready to run FORTH system.

    https://github.com/uho/F-PC F-PC - a Forth system optimized for IBM-PC, XT and AT machines running DOS

    https://www.latte.org/latte.htmlLatte The Language for Transforming Text

    https://en.wikipedia.org/wiki/Joe's_Own_Editor

    https://www.freebsd.org/

    https://www.debian.org/

    https://www.gentoo.org/

    https://en.wikipedia.org/wiki/Mac_Mini

    https://en.wikipedia.org/wiki/PowerPC

    https://en.wikipedia.org/wiki/Ivy_Bridge_(microarchitecture)

    https://en.wikipedia.org/wiki/Ubuntu

    https://en.wikipedia.org/wiki/Firefox

    https://en.wikipedia.org/wiki/Chromium_(web_browser)

    https://www.raspberrypi.com/products/raspberry-pi-400/

    https://www.intel.com/content/www/us/en/ark/products/series/217838/12th-generation-intel-core-i5-processors.html

    https://en.wikipedia.org/wiki/Windows_11

    Provide feedback on this episode.
  • Hacker Public Radio

    HPR4665: Pokémon GO

    19-06-2026
    This show has been flagged as Clean by the host.



    Pokémon Go (stylized as Pokémon GO) is a 2016 augmented reality (AR) mobile game developed and published by Niantic, in partnership with Nintendo and The Pokémon Company, for iOS and Android devices. The game uses GPS to locate, capture, train, and battle Pokémon. It is free-to-play, featuring a freemium model that includes local advertising and offers in-app purchases for additional in-game items. Pokémon Go launched with approximately 150 Pokémon species, with new species regularly introduced.








    -- Wikipedia.org

    Provide feedback on this episode.
  • Hacker Public Radio

    HPR4664: No Input Mixing Tutorial and How to Build a Drone Box

    18-06-2026
    This show has been flagged as Explicit by the host.

    Some links to other tutorials (in case you need a visual element, these helped me out)

    Mixing board tutorial

    https://youtu.be/H-7kQmpjBds

    Drone Box tutorial

    https://youtu.be/50C6DBsqy24

    Provide feedback on this episode.
  • Hacker Public Radio

    HPR4663: The hallway track at T-DOSE

    17-06-2026
    This show has been flagged as Clean by the host.

    T-DOSE

    TDOSE 2027

    Mark you calendars #TDOSE 2027 on 5 and 6 June '27 in the Weeffabriek, Geldrop.

    T-DOSE

    Info Booth

    Hackalot

    Laptop Revive

    Free Software Foundation Europe

    Doeidag and Banray

    Debian

    Angry Nerds Podcast

    Freie Software Freunde - Free Your Model Train

    Hacker Public Radio: The community Podcast

    UBports

    Adfinis

    Credits

    The Technical Dutch Open Source Event (T-DOSE)

    In
    hpr4641 :: Technical Dutch Open Source Event (T-DOSE)
    , Ken interviewed Peter van Ginneken about the
    T-DOSE
    conference.

    The Technical Dutch Open Source Event (T-DOSE) is a free conference to promote the use and development of Open Source software. This event has is organised yearly since 2006 in the Brainport region, near Eindhoven, The Netherlands. During this event, Open Source projects, developers and visitors can exchange ideas and knowledge.

    Peter van Ginneken Opens the Event.

    We catch up with him at the start of Day 2.

    Info Booth

    The backbone of any event is the Info booth and catering.

    Here we talk to Nick Hibma who when not serving on the Info Booth is treasurer of the T-DOSE organisation.

    Ready to serve sandwitches, sell T-Shirts, Magic Mugs, and
    club-mate

    T-Shirts

    club-mate

    Magic Mugs

    Hackalot

    Hackalot is the Eindhoven and surrounding area hackerspace. A hackerspace is a place where hackers can work on their own or collaborative projects. You can work and talk together, but you can also do your own thing. Together we can also purchase a lot of cooler tools such as lasercutters and 3d printers. Often there is no suitable place for equipment at home. So if you know someone, you are either an electronics/computer/technical hobby that got out of hand, come on by!

    Boekenwuurm at the Hackalot stand.

    The Hackalot stand.

    Boekenwuurm@hsnl.social

    boekenwuurm.nl

    Hackalot

    Laptop Revive

    Laptop Revive collects discarded laptops, that are still working. We then install Linux Mint to provide a working laptops to students who cannot afford laptops. We are socially involved, sustainable and open.

    Alex Kok Laptop Revive

    Laptop Revive

    Free Software Foundation Europe

    Free Software Foundation Europe (FSFE) information booth, with information material, stickers and merchandise.

    Nico was so busy that we were unable to snag an interview this time. However check out our talk with him at the
    NLUUG Spring Conference 2026
    .

    Free Software Foundation Europe

    Doeidag and Banray

    We also interviewed Geert-Jan Meewisse in
    hpr4639 :: NLUUG Spring Conference 2026
    but this time he is here talking about
    banray.eu

    In 2025, Meta sold over seven million pairs of camera-equipped glasses that look like regular Ray-Bans. The person wearing them looks like anyone else. But these people are now products, as is everyone they interact with.

    He then also mentioned the
    Doeidag
    project where they encourage people to drop one service at a time on the first Sunday of the month

    https://doeidag.nl/

    https://banray.eu/

    Geert-Jan Meewisse Doeidag and Banray

    Debian

    The Debian Project is an association of Free Software developers who volunteer their time and effort in order to produce the completely free operating system Debian.

    Ken Talks to Joost van Baal Llić from the Debian Project

    Debian

    Angry Nerds Podcast

    Angry Nerds, met extra cyber!

    The Angry Nerds is a Dutch Language podcast about privacy and security

    It's a live show that is topical and often humorous tech podcast where a group of enthusiastic nerds discusses current technology, IT and cybersecurity topics. The hosts combine technical depth with background conversations, humor and the occasionally a good dose of cynicism. Expect conversations about everything from network infrastructures to software development, from privacy issues to bizarre tech trends.

    Ken on the Angry Nerds Podcast

    You can listen to the recording at Angry Nerds op T-DOSE 2026 deel 2 (prikkelarme versie).

    Angry Nerds Podcast

    Freie Software Freunde - Free Your Model Train

    We are a non-profit organization. We are committed to Free Software and Open Standards. Software is not just technology, it's an important part of our daily life.

    We want to raise awareness of the importance of Free Software and Open Standards. That is why we are concerned with topics outside of technology: politics, education, ethics, psychology, ecology and economics, licenses, ... One of our projects is "Free your model train". Our goal is to raise awareness of the benefits of open standards.

    Birgit Hücking (@akkolady) standing at the
    freie-software.org

    The
    freie-software.org
    table with two large train loops, a smaller internal one. Two knitted Tux Mascots. And a lot of information.

    Close up of the two knitted Tux Mascot.

    @akkolady@chaos.social

    @FreieSoftwareFreunde@mastodon.social

    Freie Software Freunde

    Free Your Model Train

    https://fymt.de

    Hacker Public Radio: The community Podcast

    Hacker Public Radio is a technology focused podcast that releases shows every weekday Monday to Friday. Our shows are created by people like you, and can be on any topic that is of interest to hackers, hobbyists, makers, etc. We are a welcoming community that offers positive feedback and encourages respectful debate. This is our 21st year of operation, and we will release our 5,000th show in August. Everything we do is released under a Free Culture License. We do not vet, edit, moderate or in any way censor any of the audio you submit, we trust you to do that. We will be available to guide you in sharing your knowledge with the community. Having had a stand at FOSDEM (BE), OggCamp(UK), Linux Fest North West(US), Spectrum (FR), we are available to show you how easy podcasting can be. We will be answering your questions, and conducting interviews with anyone with anything interesting to say.

    The HPR booth.

    Hacker Public Radio

    UBports

    We are developing an open source Linux mobile OS built to be your daily driver... ...and we'd like to welcome you to our community.

    Next up is a chat with Sander Klootwijk about UBports and Ubuntu Touch. Their website has a list of
    supported devices
    .

    We talk with Sander Klootwijk

    Proof it's running on actual hardware

    Yumi The UBports Installer Mascot was not available for comment.

    Ubuntu Touch on a Fairphone

    @BallonQuartier@mastodon.nl

    UBports

    https://devices.ubuntu-touch.io/

    Adfinis

    Accelerate your business with open source-driven automation, security, cloud, and DevSecOps solutions from Adfinis, your end-to-end partner for robust, flexible IT that drives growth and innovation at any scale. Welcome to Our World Full of Open Source

    At Adfinis, we believe in the transformative power of open source technology to foster innovation, transparency, and collaboration. We are committed to providing solutions free from vendor lock-in, ensuring our clients retain full control and flexibility over their systems. Digital sustainability lies at the heart of our approach, as we strive to create technologies that not only serve the present but also support a long-term, environmentally responsible future. Additionally, we champion digital sovereignty, empowering organizations and communities to own and control their data, infrastructure, and technological destiny. These principles drive us to build a more open, sustainable, and inclusive digital world.

    Finally we chat to
    Coen hamers
    ,
    Robert de Bock
    , and
    Annebelle van Waardenburg
    from
    Adfinis
    whose sponsorship made the event possible.

    https://www.adfinis.com/en/solutions

    https://www.adfinis.com/en/career

    Credits

    Record Needle Rip

    Free Software Song

    Provide feedback on this episode.
Meer Nieuws podcasts
Over Hacker Public Radio
Hacker Public Radio is an podcast that releases shows every weekday Monday through Friday. Our shows are produced by the community (you) and can be on any topic that are of interest to hackers and hobbyists.
Podcast website

Luister naar Hacker Public Radio, Weer een dag en vele andere podcasts van over de hele wereld met de radio.net-app

Ontvang de gratis radio.net app

  • Zenders en podcasts om te bookmarken
  • Streamen via Wi-Fi of Bluetooth
  • Ondersteunt Carplay & Android Auto
  • Veel andere app-functies