《if..then..elif..then..else语句脚本》


#!/bin/bash
read -p "input your file name " file_name
if [ -d $file_name ]      //判断是否为目录
  then
        echo " this file is directory!"
elif [ -f $file_name ]      //是否为文件
  then
        echo "this file is file"
elif [ -c $file_name -o -b $file_name ]    //是否为字符设备或块设备,符合其一就ok
  then
        echo "this is block file"
else
  echo "this file unknown"
fi
 

查看下系统的块设备和字符设备
[root@redhat shellscripts]# ll /dev/sda
brw-rw----. 1 root disk 8, 0 Jun  1 10:05 /dev/sda
[root@redhat shellscripts]# ll /dev/tty
crw-rw-rw-. 1 root tty 5, 0 Jun  1 10:05 /dev/tty

相关内容