• 0 Posts
  • 107 Comments
Joined 1 month ago
cake
Cake day: December 16th, 2024

help-circle

  • Yeah, another way to do it is

    #!/bin/bash
    set -euo pipefail
    
    if [[ $# -lt 1 ]]
    then
      echo "Usage: $0 argument1" >&2
      exit 1
    fi
    

    i.e. just count arguments. Related, fish has kind of the orthogonal situation here, where you can name arguments in a better way, but there’s no set -u

    function foo --argument-names bar
      ...
    end
    

    in the end my conclusion is that argument handling in shells is generally bad. Add in historic workarounds like if [ "x" = "x$1" ] and it’s clear shells have always been Shortcut City


    Side note: One point I have to award to Perl for using eq/lt/gt/etc for string comparisons and ==/</> for numeric comparisons. In shells it’s reversed for some reason? The absolute state of things when I can point to Perl as an example of something that did it better





  • I think I mentioned it, but inverse: The only data type I’m comfortable with in bash are simple string scalars; plus some simple integer handling I suppose. Once I have to think about stuff like "${foo[@]}" and the like I feel like I should’ve switched languages already.

    Plus I rarely actually want arrays, it’s way more likely I want something in the shape of

    @dataclass(frozen=True)
    class Foo:
        # …
    
    foos: set[Foo] = …
    

  • -e is great until there’s a command that you want to allow to fail in some scenario.

    Yeah, I sometimes do

    set +e
    do_stuff
    set -e
    

    It’s sort of the bash equivalent of a

    try { 
      do_stuff()
    } 
    catch { 
      /* intentionally bare catch for any exception and error */
      /* usually a noop, but you could try some stuff with if and $? */ 
    }
    

    I know OP is talking about bash specifically but pipefail isn’t portable and I’m not always on a system with bash installed.

    Yeah, I’m happy I don’t really have to deal with that. My worst-case is having to ship to some developer machines running macos which has bash from the stone ages, but I can still do stuff like rely on [[ rather than have to deal with [ . I don’t have a particular fondness for using bash as anything but a sort of config file (with export SETTING1=... etc) and some light handling of other applications, but I have even less fondness for POSIX sh. At that point I’m liable to rewrite it in Python, or if that’s not availaible in a user-friendly manner either, build a small static binary.



  • At the level you’re describing it’s fine. Preferably use shellcheck and set -euo pipefail to make it more normal.

    But once I have any of:

    • nested control structures, or
    • multiple functions, or
    • have to think about handling anything else than simple strings that other programs manipulate (including thinking about bash arrays or IFS), or
    • bash scoping,
    • producing my own formatted logs at different log levels,

    I’m on to Python or something else. It’s better to get off bash before you have to juggle complexity in it.




  • Yeah, Rust is ultimately a different project than Go, and I suspect much of the success of Go is down to stuff like good tooling, default GC, native static binaries, generally easy concurrency, rather than stuff like having as bare-bones a language as otherwise possible. I’d suspect having a focus on fast compilation also helps draw in people from interpreted languages.

    It’s easy to write a Kubernetes microservice that performs adequately with Go, and that’s all a lot of people & teams need.




  • I suspect my habit of having an alias userctl="systemctl --user" is slightly unusual, as is running Firefox, Steam, and some other graphical programs as systemd units is somewhat unusual (e.g. mod4-enter runs systemd-run --user alacritty)

    But what I’m actually pretty sure is unique is my keyboard layout. I taught myself dvorak a summer some decades ago, but the norwegian dvorak layout has some annoyances, so I’ve made some tweaks. Used to be a Xmodmap file, but with the switch to wayland I turned it into a file in /usr/share/X11/xkb/symbols/.

    Part of what I did to teach myself dvorak and touch-typing at the same time was randomize the placement of the keycaps too. It has a side effect of being a kind of security by obscurity layer: I type quickly and confidently, but others who want to use my machines have an “uhh …” reaction.





  • esatoFuck Cars@lemmy.worldWell well well
    link
    fedilink
    English
    arrow-up
    2
    ·
    5 days ago

    It’s been widely studied in other cities already. Studying it more is ok, but at some point you gotta wonder whether we need all that many studies about whether water is wet, or if the resources and manpower could be better spent elsewhere.