← Back to context

Comment by Dylan16807

8 hours ago

> At least allow us to use names instead of numbers.

You can use /dev/stdin, /dev/stdout, /dev/stderr in most cases, but it's not perfect.

> You can use /dev/stdin, /dev/stdout, /dev/stderr in most cases

Never ever write code that assumes this. These dev shorthands are Linux specific, and you'll even need a certain minimum Linux version.

I cringe at the amount of shell scripts that assume bash is the system interpreter, and not sh or ksh.

Always assume sh, it's the most portable.

Linux != Unix.

  • It's a waste of time unless you're specifically targeting and testing mac, all of the BSDs, various descendants of Solaris, and other flavors of Unix. I wrote enough "portable shell" to run into so many quirks and slight differences in flags, in how different tools handle e.g. SIGPIPE.

    Adding a new feature in a straightforward way often makes it work only on 4/7 of the operating systems you're trying to support. You then rewrite it in a slightly different way (because it's shell — there's always 50 ways to do the same thing). This gets you to 5/7 working systems, but breaks one that previously worked. You rewrite it yet another way, fixing the new breakage, but another one breaks. Repeat this over and over again, trying to find an implementation that works everywhere, or start adding workarounds for each system. Spend an hour on a feature that should have taken two minutes.

    If it's anything remotely complicated, and you need portability, then use perl/python/go.

  • Actually, while the Actual Nodes are a linux thing, bash itself implements (and documents) them directly (in redirections only), along with /dev/tcp and /dev/udp (you can show with strace that bash doesn't reference the filesystem for these, even if they're present.)

    So, you're not wrong, but...

  • lol truly informative and clearly something no one here knew. But your terminology is inaccurate. Please change it to GNU/Linux != Unix