Files
Boria138 a70bf97774
Code check / Check code (push) Successful in 2m50s
ci: check Bash 5.1 conditional separator compatibility
Signed-off-by: Boris Yumankulov <boria138@altlinux.org>
2026-09-16 18:31:34 +05:00

37 lines
856 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cr=$(printf "\r")
status=0
for file in "$@"; do
IFS= read -r first_line < "$file" || true
case "$first_line" in
"#!"*"$cr")
echo "$file: trailing <CR> in interpreter: $first_line"
status=1
continue
;;
esac
if ! bash -n "$file"; then
echo "$file: bash -n syntax check failed"
status=1
fi
# Bash 5.1 requires a separator before then after a conditional command.
if ! awk '
/\]\][ \t]+then([ \t;]|$)/ || (continued && /^[ \t]*then([ \t;]|$)/) {
printf "%s:%d: Bash 5.1 requires a newline or semicolon before then\n", FILENAME, NR
failed = 1
}
{ continued = /\]\][ \t]*\\$/ }
END { exit failed }
' "$file"; then
status=1
fi
done
exit "$status"