file-test

Bash -G — effective group ownership

Checks whether a path has the same group ID as the shell effective group ID. Membership in a supplementary group is not equivalent to this predicate. The example assumes a fresh directory with no inherited alternate group; chgrp selects the current effective group. Run the example independently in a fresh private directory. Expected output (one item per line): owned=0; missing=1.

Formal Syntax & Structure

bash syntaxbash
[[ -G path ]]

Parameters & Attributes

NameTypeDescription
pathpathFile or directory pathname to inspect.

Return Value

exit status

0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.

Working Example

Example Snippetbash
touch samplechgrp "$(id -g)" sample || exit 1[[ -G sample ]]; printf 'owned=%s\n' "$?"[[ -G missing ]]; printf 'missing=%s\n' "$?"
Bash Reference