file-test
Bash -b — block device test
Distinguishes a block-special file from ordinary files and character devices. A positive result does not imply that reading or writing the device is appropriate. This fixture tests the false branch only; no block device is created or accessed. Run the example independently in a fresh private directory. Expected output (one item per line): regular=1; character=1.
Formal Syntax & Structure
bash syntaxbash
[[ -b 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 sample[[ -b sample ]]; printf 'regular=%s\n' "$?"[[ -b /dev/null ]]; printf 'character=%s\n' "$?"