Open main menu

CDOT Wiki β

Changes

BASH Exit Status

64 bytes added, 15:39, 12 October 2008
The test Command
= The test Command =
BASH has a built-in test command (similar to <code>/bin/test</code>) which can perform basic string and integer comparisons using these operators(results are returned as an exit code):
{|class="mediawiki" border="1"
|<nowiki>-e</nowiki>
|File exists
|[ -e /etc/passwd]
|-
|<nowiki>-r</nowiki>
|File is readable
|[ -r /etc/hosts]
|-
|<nowiki>-w</nowiki>
|File is writable
|[ -w /tmp]
|-
|<nowiki>-x</nowiki>
|File is executable
|[ -x /usr/bin/ls]
|-
|<nowiki>-f</nowiki>
|File is a regular file
|[ -f /dev/tty]
|-
|<nowiki>-d</nowiki>
|File is a directory
|[ -d /dev/tty]
|}