[Shell] the basis of test conditions

EXAMPLE 1 determines whether a directory exists

#! / usr / bin / bash 
back_dir = / var / mysql_back
 if ! test - the $ back_dir; then 
    mkdir - p $ back_dir 
fi

Example 2 Installation software

#!/usr/bin/bash
if [ $UID -ne 0 ];then
    echo "no permission"
    exit
fi
yum -y install httpd

Test file (file or directory operator)

-d the Test / Home 
echo $ ? 
Output: 0 
the Test -d / home1111 
echo $ ? 
Output: 1 
[ -e dir | File] directory or file to determine whether there is 
[ - d dir] and determine whether there is a directory 
[ - f File ] and determines whether there is a file 
[ - if r file] current user has read access to the file 
[ - X file] 
[ - W file] 
[ -L file] determines whether the link

 

Guess you like

Origin www.cnblogs.com/zhangshengxiang/p/11536616.html