file-test
Bash -w — write access test
Checks whether the shell identity can write the specified file or directory at the time of the test. It does not imply that creating, deleting or replacing a different pathname will succeed. Run the mode-bit example as a non-root user in a private directory. Run the example independently in a fresh private directory. Expected output (one item per line): writable=0; blocked=1.
Formal Syntax & Structure
bash syntaxbash
[[ -w 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
touch samplechmod 600 sample[[ -w sample ]]; printf 'writable=%s\n' "$?"chmod 400 sample[[ -w sample ]]; printf 'blocked=%s\n' "$?"