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

#!/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
发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>