Analyzing the shell script text type 2 (argument to the script)

Analyzing the shell script text type 2 (argument to the script)

#!/bin/bash
if [ "$#" -lt 1 ]; then                                    #判断脚本参数个数,当参数个数小于1时,给出脚本执行方式
        echo "Usage:./judge_file_arg.sh ARG1 [ARG2...]"
        exit 2                                                  #定义错误退出码
fi
if [ ! -e "$1" ]; then                                     #判断给出的文件是否存在,不存在推出脚本
        echo "no such file"
        exit 3
fi
if [ -f "$1" ]; then                                       #判断文件是否为普通文本
        echo "This is normal file"
elif [ -d "$1" ]; then                                   #判断是否为目录
        echo "This  is directory"                               
else
        echo "This  is other type file"
fi

Guess you like

Origin blog.51cto.com/11342825/2424440