SC3067 – ShellCheck Wiki

See this page on GitHub

Sitemap


In POSIX sh, test -O is undefined.

Problematic code:

if [ -O file ]
then
  echo "File is owned by you"
fi

Correct code:

if [ -n "$(find file -prune -user "$(id -u)")" ]
then
  echo "File is owned by you"
fi

Rationale:

test -O is a bash/ksh/dash/ash extension to check whether the file is owned by you.

To ensure compatibility with other shells, you can use find -user "$(id -u)".

Exceptions:

If you expect your shell to support test -O, specify this explicitly in the shebang (or with # shellcheck shell=dash directive).


ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.