27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

(( 5 − 5 )) # 0<br />

echo "Exit status of \"(( 5 − 5 ))\" is $?." # 1<br />

(( 5 / 4 )) # Division o.k.<br />

echo "Exit status of \"(( 5 / 4 ))\" is $?." # 0<br />

(( 1 / 2 )) # Division result < 1.<br />

echo "Exit status of \"(( 1 / 2 ))\" is $?." # Rounded off to 0.<br />

# 1<br />

(( 1 / 0 )) 2>/dev/null # Illegal division by 0.<br />

echo "Exit status of \"(( 1 / 0 ))\" is $?." # 1<br />

# What effect does the "2>/dev/null" have?<br />

# What would happen if it were removed?<br />

# Try removing it, then rerunning the script.<br />

exit 0<br />

7.2. File test operators<br />

Returns true if...<br />

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

−e<br />

−f<br />

−s<br />

−d<br />

−b<br />

−c<br />

−p<br />

−h<br />

−L<br />

−S<br />

−t<br />

−r<br />

−w<br />

−x<br />

file exists<br />

file is a regular file (not a directory or device file)<br />

file is not zero size<br />

file is a directory<br />

file is a block device (floppy, cdrom, etc.)<br />

file is a character device (keyboard, modem, sound card, etc.)<br />

file is a pipe<br />

file is a symbolic link<br />

file is a symbolic link<br />

file is a socket<br />

file (descriptor) is associated with a terminal device<br />

This test option may be used to check whether the stdin ([ −t 0 ]) or stdout ([ −t 1 ]) in<br />

a given script is a terminal.<br />

file has read permission (for the user running the test)<br />

file has write permission (for the user running the test)<br />

Chapter 7. Tests 46

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!