Chinaunix首页 | 论坛 | 博客
  • 博客访问: 243115
  • 博文数量: 68
  • 博客积分: 2802
  • 博客等级: 少校
  • 技术积分: 614
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-11 15:38
文章存档

2013年(3)

2012年(15)

2011年(21)

2010年(29)

我的朋友

分类:

2010-03-16 17:28:20

#! /usr/bin/sh

#用Shell编程,判断一文件是不是块或字符设备文件,如果是将其拷贝到 /dev 目录下。
#tips:使用文件测试来做

INPUTERRO=66
#有否文件

if [ -z "$1" ]
then
  echo "There is no input file!please input sourc file!\n"
  exit ${INPUTERRO}
#  exit 0
fi


if [ ! -e "$1" ]
then
  echo "input file is not exist!\n"
  exit $INPUTERRO
#  exit 0
fi

if [ -f "$1" ]
then
  echo "it is a regul-flie! no a device file!\n"
  exit $INPUTERRO
fi


#有无块或字符设备文件。有则复制到/dev/目录下并返回


if [ -b "$1" -o -c "$1" ]
then
  cp  -i "$1" /dev
  echo "file '$1' move to /dev!\n"
fi

exit 0

####################参考脚本#########################3
'''
#!/bin/bash
#1.sh
#fiile executable: chmod 755 1.sh
echo -e "The program will Judge a file is or not a device file.\n\n"
read -p "Input a filename : " filename
if [ -b "$filename" -o -c "$filename" ]
then
       echo "$filename is a device file" && cp $filename /dev/ &
else
       echo "$filename is not a device file" && exit 1
fi
'''
阅读(398) | 评论(0) | 转发(0) |
0

上一篇:DIVE INTO PYTHON 中文版

下一篇:shell 简介

给主人留下些什么吧!~~