[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#490604: debian-policy: please don't state that scripts working under dash are 'probably' policy-compliant



Russ Allbery wrote:

> --- a/policy.sgml
> +++ b/policy.sgml
> @@ -7968,10 +7968,12 @@ fname () {
[...]
> -         as its interpreter. If your script works with <prgn>dash</prgn>
> -         (originally called <prgn>ash</prgn>), it probably complies with
> -         the above requirements, but if you are in doubt, use
> -         <file>/bin/bash</file>.
> +         as its interpreter.  Checking your script
> +         with <prgn>checkbashisms</prgn> from
> +         the <package>devscripts</package> package or running your script
> +         with <prgn>posh</prgn> may help uncover violations of the above
> +         requirements.  If in doubt whether a script complies with these
> +         requirements, use <file>/bin/bash</file>.

I tend to find checking syntax ($shell -n) and running with "bash",
"dash", "mksh", and "ksh93" more useful than posh for checking that a
script is portable to the main POSIX-style shells in common use.  I
want posh to work for this kind of thing, but in some cases it is not
different enough from bash to catch problems.

Some scripting portability pitfalls, taken from the git commit log:

 - 'test "$foo" == "$bar"' (Checkbashisms and posh catch it)

 - brace expansion (Checkbashisms and posh catch it)

 - ++i in arithmetic expansion (Checkbashisms catches it.  Posh doesn't)

 - 'echo "$var"', var='foo\bar' (Posh catches it.  Checkbashisms doesn't)

 - "printf '\xc3\xa4\n'" (Neither posh nor checkbashisms catches it)

 - 'local var=$val', val='foo bar' (Posh catches it; checkbashisms doesn't)

 - It is not predictable when starting a new command in the shell will
   start a new process.  Scripts notice this by using $!, $PPID, "kill",
   and so on.  (Testing as many different shells as possible helps a
   lot --- bash, dash, ksh93, and mksh behaviors are all different.)

 - 'var=newval function_call; echo $var' (Neither posh nor
   checkbashisms catches it).  Yes, the dash/ksh93 behavior is
   explicitly permitted in POSIX.

 - 'var=$((echo hi) | head)' (Neither posh nor checkbashisms catches it)

Hope that helps,
Jonathan



Reply to: