4 comments

  • Muhammad5231 hour ago
    This post is nice: the writer first explains a problem, using a simple example. In the next section, they reflect a bit about the problem, and then they casually mention two tools they built. In my opinion, this is amazing: you sponsor you project, while also making the problem it solves clear: use their tool to test how portable your code is
  • echoangle2 hours ago
    Pretty bad argument. If it’s not defined by POSIX, it’s not POSIX compatible if you rely on a specific behavior.<p>If you only use defined behavior and it works, it is compatible.<p>It’s like saying C99 isn’t a compiler. True, but you can still write C99 code, right?
    • smitty1e1 hour ago
      &gt; C99 isn’t a compiler.<p>Sure, but the pojt here is that if we say &quot;Write in X&quot; we generally understand it to mean &quot;Treat X like a standard and don&#x27;t get too colloquial with the stylings.&quot;<p>Pedantry is worthwhile, but it can be a diminishing returns game.
      • eqvinox1 minute ago
        Feels like you missed the point.<p>On the example of &#x27;echo \n&#x27; - it&#x27;s not defined in POSIX, therefore a script written in &quot;POSIX shell&quot; must simply never hit that case.<p>TFA claims you can&#x27;t target POSIX shell. That&#x27;s silly, of course you can. The question is, what tools are there to check for compliance.
  • sdovan138 minutes ago
    If your environment is POSIX, testing scripts with tool written in POSIX shell, like shellspec[1], might also be a choice.<p>[1] <a href="https:&#x2F;&#x2F;shellspec.info&#x2F;" rel="nofollow">https:&#x2F;&#x2F;shellspec.info&#x2F;</a>
  • jmclnx1 hour ago
    Will not build without docker, so I am out of luck. This tells me this is not portable, even to some Linuxes.
    • Joker_vD3 minutes ago
      Strict POSIX conformance is arguably worse. I mean, have you seen what it advises for shebangs? First of all:<p><pre><code> The shell reads its input from a file (see sh), from the -c option or from the system() and popen() functions defined in the System Interfaces volume of POSIX.1-2017. If the first line of a file of shell commands starts with the characters &quot;#!&quot;, the results are unspecified. </code></pre> Ah, so shebangs are not required to be supported, already a great start.<p><pre><code> Applications should note that the standard PATH to the shell cannot be assumed to be either &#x2F;bin&#x2F;sh or &#x2F;usr&#x2F;bin&#x2F;sh, and should be determined by interrogation of the PATH returned by getconf PATH, ensuring that the returned pathname is an absolute pathname and not a shell built-in. [...] Furthermore, on systems that support executable scripts (the &quot;#!&quot; construct), it is recommended that applications using executable scripts install them using getconf PATH to determine the shell pathname and update the &quot;#!&quot; script appropriately as it is being installed (for example, with sed). For example: # # Installation time script to install correct POSIX shell pathname # # Get list of paths to check # Sifs=$IFS Sifs_set=${IFS+y} IFS=: set -- $(getconf PATH) if [ &quot;$Sifs_set&quot; = y ] then IFS=$Sifs else unset IFS fi # # Check each path for &#x27;sh&#x27; # for i do if [ -x &quot;${i}&quot;&#x2F;sh ] then Pshell=${i}&#x2F;sh fi done # # This is the list of scripts to update. They should be of the # form &#x27;${name}.source&#x27; and will be transformed to &#x27;${name}&#x27;. # Each script should begin: # # #!INSTALLSHELLPATH # scripts=&quot;a b c&quot; # # Transform each script # for i in ${scripts} do sed -e &quot;s|INSTALLSHELLPATH|${Pshell}|&quot; &lt; ${i}.source &gt; ${i} done </code></pre> Marvelous. What a robust foundation of useful and hard-to-misuse utilities.