1. 变量赋值
语法:var="saaaa"
PS: 等号两边不能有空格
2. 脚本示例如下:
#!/bin/sh
# Get bug activity info
# usage get_bug_activity <bug_id_list_file>
if [ $# -lt 2 ]; then
echo "Usage:";
echo "$0 <blk_pair_id_list_file> <dir>";
exit;
fi
if [ ! -d $2 ]; then
echo "make DIR $2";
mkdir $2;
fi
echo -e "processing bug list file 33[1;31m$1 33[m";
n=0
m=0
cat $1 | while read line # read file $1 line by line
do
BugID=`echo ${line%%[A-Z]*} | sed 's/[ ]*$//g'`; # get Bugid from each line $line,
# and remove the space of the string tail
# PS: BugID="***" right; BugID = "***" wrong
# There should no space between "=
let n=n+1;
echo -e " 33[1;35m$n 33[m $BugID";
rfile="$2/a$BugID.htm";
if [ ! -f "$rfile" ]; then
curl "https://bugs.eclipse.org/bugs/show_activity.cgi?id=$BugID" -o "$rfile";
else
let m=m+1;
echo -e " 33[1;31mfile existed... 33[m $m duplicated";
fi
done
echo "finished";
3. 示例讲解
echo -e "processing bug list file 33[1;31m$1 33[m";
: 用来设置变量$1 的颜色。