demo
判断命令字符串形式相等 [[ ]] 左右都有空格,
!/bin/bash
result=date
echo $result
if [[ "$result"=="date" ]] ;then
echo "当前命令的字符串形式和"date"字符串相等 "
else
echo "当前命令的字符串形式和"date"字符串不相等"
fi
result=`date`
echo $result
使用:
shell变量=不能有空格。
构造字符串数组,中间使用”空格“区分,而不是”逗号“
字符串数组遍历:很麻烦。如下:
字符串匹配: 两个方括号中间都要有空格,中间也要有空格。
模糊匹配符号: = ~
tem_array=('platform/fexp/bin.des' 'platform/fexp1/server.gflags' 'platform/fexp/server.ini')
for ini in ${tem_array[@]} ;do
#echo $ini
if [[ "$ini" =~ .*\.ini$ ]] ;then
echo $ini
fi
done
python中直接使用 in也能对字符串进行匹配如
tem_array = ['platform/fexp/bin.des','platform/fexp1/server.gflags','platform/fexp/server.ini']
for tem in tem_array:
if "ini" in tem:
print("tem",tem)
#!/bin/bash
CUR_PATH=`pwd`
TARGET_BRANCH="master"
SUFFIX=""
BASE_POINT=`git merge-base origin/${TARGET_BRANCH}${SUFFIX} HEAD`
#BASE_POINT=`git rev-parse origin/${TARGET_BRANCH}${SUFFIX}`
REVIEWER_URL=http://hookserver.jd.local/git_diff/
HTMLDIFF=${CUR_PATH}/godiff
cd $CUR_PATH
# 全量配置的目录, 只需要和自己比diff
for name in `git diff ${BASE_POINT} --name-only\
|grep -E "platform/(f[i,s,z,t]a|fs[i,t]dmp|f[s,z]customer|fbusiness)/.*(.*\.ini)$"`;do
#|grep -E "platform/(f[i,s,z,t]a|fs[i,t]dmp|f[s,z]customer|fbusiness)/.*(.*\.des|.*\.ini|.*\.gflags|.*\.xml|.*\.py|.*\.txt)$"`;do
if [ ! -f "$name" ]; then
echo_trace "Delete file $name"
continue
fi
ini2 = `echo $name |grep -E "platform/(f[i,s,z,t]a|fs[i,t]dmp|f[s,z]customer|fbusiness)/.*(.*\.ini)$"`
if [[ "$ini2"!="" ]] ;then
git diff origin/${TARGET_BRANCH}${SUFFIX}:$sa_file_name $name >> patch
echo $name >> name.txt
fi
done
# fexp 与全量的diff
for name in `git diff ${BASE_POINT} --name-only\
|grep -E "platform/fexp.*/.*(.*\.ini)$"`;do
#|grep -E "platform/fexp.*/.*(.*\.des|.*\.ini|.*\.gflags|.*\.xml|.*\.py|.*\.txt)$"`;do
if [ ! -f "$name" ]; then
echo_trace "Delete file $name"
continue
fi
#需要对比的文件
file_name=${name##*/}
#cr中修改的平台名称
cr_platform=`echo $name |awk -F"/" 'OFS="/"{$NF="";print}'`
#cr平台同步的具体哪个全量平台
platform_name=`cat $cr_platform/data.des |awk 'END{print}'|sed 's/.*feature_server_dict\/\(.*\)/\1/'|cut -d '/' -f1 `
#platform_name=`cat $cr_platform/data.des |awk 'END{print}'|awk -F"feature_server/" '{print $2}'|awk -F"|" '{print $1}'`
sa_file_name=`echo platform/${platform_name}/${file_name}`
# git diff origin/${TARGET_BRANCH}${SUFFIX}:$sa_file_name $name #>> patch
# echo "global_name2222222"
ini2 = `echo $name |grep -E "platform/fexp.*/.*.*\.ini$"`
echo $ini2
if [[ "$ini2"!="" ]] ;then
echo "非空,是ini文件"
git diff origin/${TARGET_BRANCH}${SUFFIX}:$sa_file_name $name >> patch
echo "yg_name"
echo $name
echo $name >> name.txt
fi
# echo "_name"
# echo $name
# echo $name >> name.txt
done
demo