SC3066 – ShellCheck Wiki

See this page on GitHub

Sitemap


In POSIX sh, test -G is undefined.

Problematic code:

if [ -G file ]
then
  echo "File is owned by your effective group"
fi

Correct code:

if [ -n "$(find file -prune -group "$(id -g)")" ]
then
  echo "File is owned by your effective group"
fi

Rationale:

test -G is a bash/ksh/dash/ash extension to check whether the file is owned by your effective group.

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

Exceptions:

If you expect your shell to support test -G, 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.