file-test

Bash -c — character device test

Identifies a character-special file. For example, /dev/null on Linux is a character device. The test checks metadata, not whether the device is usable or safe to open. Run the example independently in a fresh private directory. Expected output (one item per line): null=0; regular=1.

Formal Syntax & Structure

bash syntaxbash
[[ -c 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 sample[[ -c /dev/null ]]; printf 'null=%s\n' "$?"[[ -c sample ]]; printf 'regular=%s\n' "$?"
Bash Reference