Shell expectations: decide and document shell scripting pattern, expectation, and usage within this chart
Summary
The following discussion from !461 (merged) should be addressed:
-
@pguinoiseau started a discussion: (+6 comments) @clemensbeck the script should run with plain
sh
if you remove thefunction
keyword instead, no need forbash
:- #!/bin/bash - function signal_handler() { + #!/bin/sh + signal_handler() {
If it is the intent that all scripting of this chart be fully POSIX compliant, then all existing scripts should be evaluated for function as such. That should then be documented, and any reference to shell-specific patterns, such as keywords or array functions, should be removed.
If it is the intent that scripting be compliant with the declared shebang statements (#!/bin/bash
or the like), then we should be consistent with out declaration and use of bash
, and not rely upon sh
which is often a symlink and opinionated based on a distribution's default environment.
Details
- The script in question is declared as written in and for
bash
via#!/bin/bash
- MVC was to have the scripting explicitly call
bash
vssh
, per#!
line. - We've chosen to implement around the constraint of the environments preferred replacement of
sh
, allowing non-bash
via removal offunction
keyword.
- Ubuntu defaults to
dash
. - Alpine image (default of this chart) defaults to
ash
. - Both have
bash
installed.
$ docker run -ti --rm --entrypoint '' registry.gitlab.com/gitlab-org/gitlab-runner bash
root@f0d8c705ada0:/# which sh
/usr/bin/sh
root@f0d8c705ada0:/# ls -l $(which sh)
lrwxrwxrwx 1 root root 4 Jul 18 2019 /usr/bin/sh -> dash
root@f0d8c705ada0:/# ls -l /usr/bin/*sh
-rwxr-xr-x 1 root root 1219168 Apr 18 2022 /usr/bin/bash
-rwxr-xr-x 1 root root 6806 Oct 10 09:03 /usr/bin/c_rehash
-rwsr-xr-x 1 root root 44552 Nov 29 2022 /usr/bin/chsh
-rwxr-xr-x 1 root root 137728 Jul 18 2019 /usr/bin/dash
-rwxr-xr-x 1 root root 4370 Nov 23 15:02 /usr/bin/instmodsh
lrwxrwxrwx 1 root root 4 Apr 18 2022 /usr/bin/rbash -> bash
lrwxrwxrwx 1 root root 21 Jan 19 00:02 /usr/bin/rsh -> /etc/alternatives/rsh
lrwxrwxrwx 1 root root 4 Jul 18 2019 /usr/bin/sh -> dash
-rwxr-xr-x 1 root root 764792 Jan 2 17:13 /usr/bin/ssh
root@f0d8c705ada0:/# head -n5 /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
$ docker run -ti --rm --entrypoint '' registry.gitlab.com/gitlab-org/gitlab-runner:alpine-bleeding bash
9e8bb463f517:/# which sh
/bin/sh
9e8bb463f517:/# ls -l /bin/*sh
lrwxrwxrwx 1 root root 12 Nov 30 09:34 /bin/ash -> /bin/busybox
-rwxr-xr-x 1 root root 865840 May 25 2023 /bin/bash
lrwxrwxrwx 1 root root 12 Nov 30 09:34 /bin/fdflush -> /bin/busybox
lrwxrwxrwx 1 root root 12 Nov 30 09:34 /bin/sh -> /bin/busybox
9e8bb463f517:/# head -n4 /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.18.5
PRETTY_NAME="Alpine Linux v3.18"
Acceptance
-
Decision on expectation / designed for Bash or POSIX -
This decision is documented -
If Bash: - Ensure all calls to
sh
are changed to explicitbash
- Ensure all calls to
-
If POSIX sh
:- Verify all functionality and keywords are consistent for POSIX only
- Verify existing functionality is identically replicated in this POSIX form
- Set all shebang lines to
/bin/sh