Snips of Scripts



This page will be most useful as quick references and are not of much value unless you are already familiar with shell scripting.

Quick Reference
File Test Options
-b file True if file exists and is a block special file
-c file True if file exists and is a character special file
-d file True if file exists and is a directory
-e file True if file exists
-f file True if file exists and is a regular file
-G file True if file exists and is owned by the effective group ID
-g file True if file exists and has SGID set
-k file True if file exists and has its "sticky" bit set
-l file True if file exists and is a symbolic link
-O file True if file exists and is owned by effective ID
-p file True if file exists and is a named pipe
-r file True if file exists and is a readable
-S file True if file exists and is a socket
-s file True if file exists and has a size greater than zero
-u file True if file exists and has SUID set
-w file True if file exists and is writable
-x file True if file exists and is executable
file1 -ef file2 True if both files have the same device and inode numbers
file1 -nt file2 True if file1 is newer (modification date) than file2
file1 -ot file2 True if file1 is older (modification date) than file2

String Test Options
string1 -a string2 True if both expressions are true
string1 -o string2 True if either expressions are true
-z string True if the length of string is zero
-n string True if the length of string is non-zero
string1 = string2 strings are equal
string1 != string2 strings not are equal

Integer Test Options
integer1 -eq integer2 True if integers are equal
integer1 -ge integer2 True if integer1 is greater than or equal to integer2
integer1 -gt integer2 True if integer1 is greater than integer2
integer1 -lt integer2 True if integer1 is less than integer2
integer1 -le integer2 True if integer1 is less than or equal to integer2
integer1 -ne integer2 True if integer1 is not equal to integer2

Array Options
declare -a ARRAY_1=( element1 element2 element3 ...elementN ) Create an Array in one line
echo ${#ARRAY_1[@]}Print the number of elements in the array
echo ${ARRAY_1[@]}Print all the elements in the array
echo ${ARRAY_1[3]} Print one element in the array( example prints 4th element, first is 0)




Script Snipits