Hacker News new | ask | show | jobs
by chasil 135 days ago
This has been addressed in a few realms, primarily shells.

One bash behavior oddity is that, when it is called as /bin/sh, this will work:

  $ cat pbasher
  #!/bin/sh
  alias p=printf
  p hello\ world!\\n

  $ ./pbasher
  hello world!
However, changing the shebang to #!/bin/bash results in this:

  $ ./pbasher
  ./pbasher: line 3: p: command not found
This is because an alias in a script is a POSIX.2 standard, but this historical bash did not allow this.

Forcing POSIX mode enables the alias:

  $ cat pbasher
  #!/bin/bash
  set -o posix
  alias p=printf
  p hello\ world!\\n

  $ ./pbasher
  hello world!
In the same way, platforms that care about POSIX.2 compatibility will adjust the behaviors to obtain certification, as bash has done. I saw HP-UX modify ksh88 into sh-posix, and vim also has a VIM_POSIX environment variable that enables a compliant standard mode.

There is discussion here:

https://vimhelp.org/vi_diff.txt.html

...the general GNU environment variable to trigger compliance used to be called POSIX_ME_HARDER.