Re: [slightly OT] writing "POSIX-compatible" scripts, and script analysis tools?

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

 



On 20Jul2017 06:29, robert p. j. day <rpjday@xxxxxxxxxxxxxx> wrote:
 (admittedly not an actual "fedora" topic but i'm sure i'll get some
good advice here.)

Hah. You will at least get lots of advice.

 i'm currently perusing someone else's collection of shell scripts,
and looking to add more, and want to clarify once and for all the
meaning of writing (and verifying) the "POSIX-ness" of shell scripts,
and what tools i can use to detect "bashisms" (or lack of POSIX-ness)
in scripts.

 first, can i verify that trying to keep my scripts as POSIX-compatible
as possible is a good thing? i've always assumed that, just curious as
to what others think, and how much effort they put into adhering to
the POSIX standard (thereby giving up all those cool bash extensions).

I definitely believe so. Aside from interactive use - the command prompt - it is rare that a bash (or zsh) -ism bring much value to a script, and when it does it is almost always a sign that you're verging on the complexity realm where the script would benefit from being recast in a richer language, eg Python.

Keeping your script POSIX compatible is a portability win. Your scripts start with "#!/bin/sh", which _always_ exists, and which is supposed to support the POSIX shell feature set and behaviour. Bash or zsh are not always in /bin, or even present. For example, on OpenBSD they're extras and land in /usr/local/bin.

 next, if i want to enforce POSIX-ness, is it just a matter of using
   #!/bin/sh --posix

Just use /bin/sh. Bash is supposed to go POSIX only when invoked that way (on systems where /bin/sh is bash; again, not always the case, even in Linux).

actually, i already know it's not that simple, since i'm sure i've
read that even adding that "--posix" option still leaves some
non-POSIX features active; i'll re-read the docs to verify that.

The option --posix is itself a bashism. Just avoid that option and presume posixness. Avoid the pain points if you trip over some nonPOSIXness that remains (== change your script).

 finally, pointers to shell analysis utilities? WRT fedora packages,
i've already found:
 * devscripts-checkbashisms
 * ShellCheck
and i suspect there are others.

I would like to see more in this list too. I'm sure my scripts could do with a bit of an audit, though I avoid bashisms as a matter of practice.

 so, thoughts? and any pointers to online coverage of this stuff?

There's the www.opengroup.org site, which _is_ POSIX. Start here:

 http://www.opengroup.org/standards/unix

Cheers,
Cameron Simpson <cs@xxxxxxxxxx>
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux