From 0817500dad0cb0746555811c15665f75b0c405a7 Mon Sep 17 00:00:00 2001 From: Alwin Wang <16846521+alwinw@users.noreply.github.com> Date: Thu, 31 Jul 2025 08:13:54 +1000 Subject: [PATCH] Expand stub to match other wiki entries --- SC3059.md | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/SC3059.md b/SC3059.md index 61bf9e7..ae9a090 100644 --- a/SC3059.md +++ b/SC3059.md @@ -1,3 +1,46 @@ -Case modification is not supported in dash and undefined in POSIX sh. +## In POSIX sh, case modification is undefined. -https://github.com/sbaudoin/sonar-shellcheck/blob/master/src/main/scripts/build_checks.yml \ No newline at end of file +(or "In dash, ... is not supported." when using `dash`) + +### Problematic code: + +```sh +#!/bin/sh +x='test' +echo "${x^^[t]}" +``` + +### Correct code: + +The easiest solution is to switch to a shell that *does* support name matching prefixes, like `bash`: + +```sh +#!/bin/bash +x='test' +echo "${x^^[t]}" +``` + +Alternatively, use external tools like `tr` for case conversion + +```sh +#!/bin/sh +x='test' +echo "$x" | tr 't' 'T' +``` + +### Rationale: + +Case modification in parameter expansion (e.g., `${x^^}`, `${x,,}`, `${x^}`, `${x,[pattern]}`) is a bash and ksh extension. dash and POSIX sh do not support it. + +### Exceptions: + +If you only intend to target shells that supports this feature, you can change +the shebang to a shell that guarantees support, or [[ignore]] this warning. + +You can use `# shellcheck disable=SC3000-SC4000` to ignore all such compatibility +warnings. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! +* https://github.com/sbaudoin/sonar-shellcheck/blob/master/src/main/scripts/build_checks.yml \ No newline at end of file