自己写的第一个比较复杂的脚本,纪念下

#!/bin/bash

if [ $# -ne 1 ];then
 echo "lack of filename"
 exit 1
fi

while read line
do
 NUM=`find .|grep vm$|grep -v 'auto-config.xml'|xargs grep "$line"|wc -l`
 if [ $NUM -gt 0 ];then

CHANGE_WORD=`echo $line|tr "." "_"`
 echo 'has changed value is :' $CHANGE_WORD

find .|grep vm$|grep -v 'auto-config.xml'|xargs sed -i "s/$line/$CHANGE_WORD/g"

echo 'the find command result ' $?

if [ $? -eq 0 ];then
 echo 'change value check'

CHANGE_NUM=`find .|grep vm$|grep -v 'auto-config.xml'|xargs grep $CHANGE_WORD |wc -l`
 echo "$line has changed . num is " $CHANGE_NUM

if [ $CHANGE_NUM -gt 0 ];then
 echo 'change value success'
 else
 echo 'change value false'
 fi
 fi

fi

done < $1

作者: inter12

在这苦短的人生中,追求点自己的简单快乐

发表评论

电子邮件地址不会被公开。 必填项已用*标注