一、构造字符串
直接构造
STR_ZERO=hello STR_FIRST="i am a string" STR_SECOND='success' |
重复多次
#repeat the first parm($1) by $2 times strRepeat() { local x=$2 if [ "$x" == "" ]; then x=0 fi local STR_TEMP="" while [ $x -ge 1 ]; do STR_TEMP=`printf "%s%s" "$STR_TEMP" "$1"` x=`expr $x - 1` done echo $STR_TEMP } |
举例:
STR_REPEAT=`strRepeat "$USER_NAME" 3`
echo "repeat = $STR_REPEAT"