您的位置:首页 > 运维架构 > Shell

shell 判断文件是否存在 并且 循环读取

2012-06-05 10:33 537 查看
#!/bin/sh
if [ $# -gt 1 ]; then 空格也要注意
echo "Uage: $0[FileName]"
exit 1

elif [ $# -eq 1 ]; then
myFileName=$1
echo $myFileName
else
myFileName=$0
echo "/home/hadoop/"$myFileName
fi

if [ ! -f"$file" ];then //!和-f 之间要有空格
echo "$myFileName does not exit!"
exit 1
fi

MY_LINE_NO=1
while read MY_LINE
do
echo "$MY_LINE:$MY_LINE_NO"
MY_LINE_NO=$((MY_LINE_NO+1))
done<$myFileName
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: