<div dir="ltr">Hello,<div><br></div><div>I'd like to talk about bash for a minute(*).<br><div><br></div><div style>There are quite a couple of shell scripts in dune-common, some with the shebang-line /bin/bash and others with /bin/sh. Rumor has it(**), recent bash features should not be used. Judging by some of the code, no bash features at all should be used, judging by other code, some can be.</div>

</div><div style><br></div><div style>I'd like some clarity: what version of bash can be relied upon and where (I take it scripts that are only supposed to be run by developers have different requirements than, say, dunecontrol).<br>

</div><div style><br></div><div style><div>(*) The minute is a lie.</div><div>(**) I could not find anything on the topic on <a href="http://dune-project.org">dune-project.org</a> but maybe I did not look hard enough.<br>

</div><div><br></div></div><div style><br></div><div style>Even if it is decided (or already has been) that e.g. Version 2.05b of bash can be relied upon, hardly anyone will know what the implications are. Let me elaborate on that for a bit.<br>

</div><div style><br></div><div style>When a bash feature has been introduced can be answered by a look at the NEWS file of bash. For each version, there's a list of new features, each with an associated letter, so that one can refer to them by a handle like 3.2 (b).<br>

</div><div style><br></div><div style>Here's a quick run-down of some features of interest:</div><div style><br></div><div style>  posix shell: $(cmd) to capture output of a command</div><div style>  2.02 (e): [[ command (a replacement for `test` or `[`)</div>

<div style>  2.05b (n): <<< "here-string" operator<br></div><div style><div style>  2.05b (g): [:word:] character classes<br></div><div>  4.0 (hh): ${var,}, ${var,,}, ${var^}, ${var^^}, etc.</div><div>
<br>
</div><div style>(I did not mention regular expressions here, since their history in bash is a bit messy and one only really wants to use them with bash 4 even though they were introduced earlier).</div><div style><br></div>

<div style>Here are some scenarios.</div><div><br></div><div style>(1) If we at least rely on posix shell, we can still use $(cmd), which is currently mixed with `cmd`. It behaves a lot nicer w.r.t. e.g .nesting</div><div style>

<br></div><div style>(2) If we rely at least on version 2.02 of bash (from '98 afaict), we can use [[ in place of test or [. We already implicitly do:<br></div></div><div style><div style><br></div><div style>test:</div>

<div style><div><div>  bin/dunecontrol:10:if test -z $MAKE; then</div><div>  bin/duneproject:187:  while [ -z $PROJECT ]; do</div><div>  bin/duneproject:218:  while [ -z $VERSION ]; do</div><div>  bin/duneproject:221:  while [ -z $MAINTAINER ]; do</div>

<div>  lib/dunemodules.lib:16:if test -z $GREP; then</div><div>  lib/dunemodules.lib:167:  if test -z $DUNE_CONTROL_PATH; then</div></div><div><br></div><div style>Since the arguments are not quoted here, if it expands to nothing, old shells will choke on this and signal a syntax error. In bash, test, [, and [[ are just synonyms and [[ handles quoting properly; In particular, we do not need to write</div>

<div style><br></div><div style>  test "x" = "x$var"</div><div style><br></div><div style>anymore; a plain [[ -z $var ]] will do.</div><div><br></div><div style>(3) If we rely at least on bash 2.05b (from '02), this code can stay, too:</div>

<div><br></div><div>here-string:<br></div><div><div><div>  lib/dunemodules.lib:589:        local lowercase=`tr 'A-Z' 'a-z' <<< $1`</div><div>  lib/dunemodules.lib:590:        local uppercase=`tr 'a-z' 'A-Z' <<< $1`</div>

<div>  lib/dunemodules.lib:625:        local lowercase=`tr 'A-Z' 'a-z' <<< $1`</div><div>  lib/dunemodules.lib:626:        local uppercase=`tr 'a-z' 'A-Z' <<< $1`</div></div>

<div><br></div><div>character classes:</div><div>  lib/dunemodules.lib:447:  echo ${@//[[:punct:]]/_}</div><div><br></div><div>( Rant: Rather than [[:punct:]] one could just use [:punct:] here; the double brackets only serve to join multiple character classes, as in [[:space:][:punct:]]. )</div>

</div><div><br></div><div>If this hasn't been decided yet, my recommendation would be to rely on bash 2.05b and thus a shell from 2002.<br></div><div style><br></div><div style><br></div><div style>Elias</div></div></div>

</div>