Skip to content
Vidar Holen edited this page Apr 11, 2025 · 1 revision

In POSIX sh, test -k is undefined.

Problematic code:

if [ -k file ]
then
  echo "File has sticky bit set"
fi

Correct code:

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!

ShellCheck

Each individual ShellCheck warning has its own wiki page like S001. Use GitHub "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally