Created SC3065 (markdown)

Vidar Holen
2025-04-11 14:32:39 -07:00
parent 4d10c35ba3
commit 44c787c795

30
SC3065.md Normal file

@@ -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!