#! /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
'''
阅读(405) | 评论(0) | 转发(0) |