Use Python for Scripting

https://news.ycombinator.com/rss Hits: 2
Summary

👋 – seems like you want to read stuff in Norwegian. Good news! This is available over at Kodemaker’s blog in Norwegian. We all like to use the simplest tool that solves our problem, but it’s not always optimal in the long run, nor when you want to run it on multiple machines. Say, for example, that you have a shell script that builds your project. You want to ensure you can call the script from different folders, so the first thing you want to do is to find the root of the project and make that the working directory: SCRIPT_PATH="$(readlink -f "$0")" PROJECT_ROOT="$(dirname "${SCRIPT_PATH}")" cd "${PROJECT_ROOT}" After that, because you have a bug with some build artefacts being stale and cached, you want to remove all the artefacts you’ve built before. That ensures we don’t have any old crap left from an earlier build: find build gen -type f \( -name '*.o' -o -name '*.a' \) -print0 \ | xargs -0 -r rm Of course, we want a build signature for the release, so we put the build date and git commit into a version file: BUILD_DATE="$(date -d 'now' +%F)" cp version.template build/version.txt sed -i "s/@VERSION@/${COMMIT_TAG:-dev}/" build/version.txt sed -i "s/@BUILD_DATE@/${BUILD_DATE}/" build/version.txt Finally, we build the project with whatever build command(s) the project relies on. There are several issues here. For me, this script will work great. But for a Mac user, all these steps will fail! The calls to readlink, find, xargs, date and sed all depend on functionality that’s provided by the GNU versions (Linux) of these programs, and they don’t exist or don’t work the same way in the BSD versions (Mac). Similarly, there are a bunch of arguments that work on Mac and not on Linux. There are ways around all of these problems, but they aren’t elegant. And if you’re only familiar with either Mac or Linux, you’ll often be surprised when the tool doesn’t work on the other OS. This is probably most annoying for Mac users who want to modify a script running on a CI machine,...

First seen: 2025-12-12 14:44

Last seen: 2025-12-12 15:45