From 44c787c7951d1ba46d0a948bd69ab668c56b0eb3 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Fri, 11 Apr 2025 14:32:39 -0700 Subject: [PATCH] Created SC3065 (markdown) --- SC3065.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 SC3065.md diff --git a/SC3065.md b/SC3065.md new file mode 100644 index 0000000..ed7dcdd --- /dev/null +++ b/SC3065.md @@ -0,0 +1,30 @@ +## In POSIX sh, test -k is undefined. + +### Problematic code: + +```sh +if [ -k file ] +then + echo "File has sticky bit set" +fi +``` + +### Correct code: + +```sh +if [ -n "$(find file -prune -perm /1000)" ] +then + echo "File has sticky bit set" +fi +``` +### Rationale: + +`test -k file` and `[ -k file ]` are not defined by POSIX. To ensure compatibility with all target systems, use `find` instead. + +### Exceptions: + +None. If you are targeting a shell that supports `test -k`, specify it in the shebang. + +### Related resources: + +* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc! \ No newline at end of file