提取颜色配置,保存颜色到文件,linux shell脚本 #!/bin/sh FILENAME=$1/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs # 可换为$1 NEW_COLOR_FILE=$2 if [ ! -f $FILENAME ];then echo "配置文件[$FILENAME]不存在" exit 1 fi if [ -z $NEW_COLOR_FILE ];then echo "没有指定新颜色配置文件" exit 1 fi REPLACE_REGEX="^semanticHighlighting" echo "保存颜色文件[$NEW_COLOR_FILE]" grep $REPLACE_REGEX $FILENAME > $NEW_COLOR_FILE exit $? 从文件恢复到配置文件 #!/bin/sh FILENAME=$2/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs NEW_COLOR_FILE=$1 if [ ! -f $NEW_COLOR_FILE ];then echo "新颜色配置文件[$NEW_COLOR_FILE]不存在" exit 1 fi if [ ! -f $FILENAME ];then echo "eclipse配置文件[$FILENAME]不存在" exit 1 fi echo "删除已有的颜色配置" REPLACE_REGEX="^semanticHighlighting" INFO=$(grep $REPLACE_REGEX $FILENAME) echo "$INFO" sed -i -e "/$REPLACE_REGEX/d" $FILENAME echo "追加新颜色配置" cat $NEW_COLOR_FILE >> $FILENAME exit $?