file-test
Bash -g — set-group-ID mode bit
Checks the set-group-ID bit, not group ownership or effective access. On many Unix filesystems the bit on a directory affects group inheritance. Use only an owned directory in this exercise; no executable is made privileged. GNU chmod may preserve directory set-group-ID bits when using a numeric mode, so clear the bit explicitly with chmod g-s. Run the example independently in a fresh private directory. Expected output (one item per line): set=0; cleared=1.
Formal Syntax & Structure
bash syntaxbash
[[ -g path ]]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | path | File 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
mkdir samplechmod 2750 sample || exit 1[[ -g sample ]]; printf 'set=%s\n' "$?"chmod g-s sample[[ -g sample ]]; printf 'cleared=%s\n' "$?"