0

I use zsh as my shell, and rbenv to manage my Ruby versions. I am diving into rbenv's internals to learn how it works. I type

vim `which bundle`

into my terminal and I see the following code:

  1 #!/usr/bin/env bash
  2 set -e
...

After the shebang, the first line of code is set -e. Wanting to learn more about set, I type man set into my terminal, but I get:

BUILTIN(1)                                                   General Commands Manual 

in response. From this I determine that set is a builtin command. From this StackOverflow answer, I interpret that to mean that builtins such as set could be implemented differently depending on which terminal the user is employing (i.e. bash vs zsh vs fish). To quote the answer:

Every Unix shell has at least some builtin commands. These builtin commands are part of the shell, and are implemented as part of the shell's source code... Different shells have different builtins, though there will be a whole lot of overlap in the basic set.

I'm assuming that the set command is part of this "basic set" that the answer refers to, right? That would make the most sense to me, since the authors of rbenv are quite experienced and I would think they're unlikely to rely on a command which could behave differently depending on the user's shell.

My question is two-fold:

  1. If my above assumption is correct, where is that "basic set" of commands defined? Is it some sort of officially-recognized, industry-wide standard that all shells must adhere to? And if so, what is that industry-wide standard known as, so I can Google it and learn more?

  2. If my assumption is wrong, and if the set terminal command is not part of some broad standard, does that mean that different shells could implement set in different ways, possibly producing different behavior? And wouldn't it therefore be dangerous for a widely-used program like rbenv to rely on such a command, since it could behave differently on different users' machines?

Richie Thomas
  • 3,073
  • 4
  • 32
  • 55
  • 1
    As long as you stick to features from POSIX sh, you're usually pretty safe. – Shawn Aug 22 '22 at 18:37
  • @Shawn OK, so I take it that POSIX is the name of the industry-wide standard that I mention in question #1 above, correct? And I see from [this link](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set) that `set` is one of the "special built-in commands" mentioned in the POSIX standard. So I'm assuming this is the reason why it's safe to rely on `set` in the manner I describe in my question. Let me know if I'm mistaken with any of these assumptions. – Richie Thomas Aug 22 '22 at 19:09

0 Answers0