• 0 Posts
  • 3 Comments
Joined 2 years ago
cake
Cake day: June 5th, 2023

help-circle
  • Yeah sorry then. It would be good to not use ls in your example though, someone who doesn’t know about that might read this discussion and think that’s reasonable.

    As for your original question, doing the foreach as a personal alias is fine. I wouldn’t use it in any script, since if anyone else reads that, they probably already know about xargs. So using your foreach would be more confusing to any potential reader I think.


  • Don’t use ls if you want to get filenames, it does a bunch of stuff to them. Use a shell glob or find.

    Also, because filenames can have newlines, if you want to loop over them, it’s best to use one these:

    for x in *; do do_stuff "$x"; done # can be any shell glob, not just *
    find . -exec do_stuff {} \;
    find . -print0 | xargs -0 do_stuff # not POSIX but widely supported
    find . -print0 | xargs -0 -n1 do_stuff # same, but for single arg command
    

    When reading newline-delimited stuff with while read, you want to use:

    cat filenames.txt | while IFS= read -r x; do_stuff "$x"; done
    

    The IFS= prevents trimming of whitespace, and -r prevents interpretation of backslashes.


  • SDL3 has a new “GPU” API, which is some kind abstraction over Vulkan/DirectX12/Metal. I imagine it hides a bunch of boilerplate as well. With this, I think, one could do a 3D render engine without having to directly use the Vulkan API (or OpenGL, …). However, the shaders need to be in whatever format the backend expects it seems.