About the difference between the Apple command line and the CentOS command line sed
Yesterday received the task of leadership, let me write a script, the purpose is to specify a certain number of self-increment, after receiving the task I think the task is too simple, but I was careless.
The main idea is to lose, so I suffer.
First I locked the target value, but the target value is not unique, I can only first lock to the target value of the ancestor target, the value of the ancestor target is the only file information. So OK, get to work.
After taking the value that is self-increment and replace, self-increment no problem, replace it with SED.
What I didn't think of was that there was a difference between the use of SED in Apple's command line and CentOS.
Centos:sed-i ' $bs #<string> $c </string>#<string> $NUM </string> #g ' $DIR $filemac:sed-i "' $b s# <string> $c </string>#<string> $NUM </string> #g ' $DIR $file
A couple more "", The Pit is dead, thank http://blog.csdn.net/dawn_moon/article/details/8547408
The thought of command line success, instant Meimei, but one put into the script, an instant explosion.
The reason is that the script runs, does not show the two parameters $b and S, after my repeated pairs of double quotation marks, single quotation marks, single quotation marks, double quotation marks, double quotation marks, single quotation marks and double quotes plus single quotation marks, no results.
Later, a space was added between $b and S, and the blood was resurrected.
Below is I write the garbage script, hope can help to novice.
Apple system command line #!/bin/bashdir=/users/admin/config/teacher/develop/file=info.plist.oriif [$USER =admin]; Then echo "This user is admin" CP $DIR $file $DIR $file.bak a= ' cat-n $DIR $file|grep "<key>cfbundleversion< ;/key> "|awk ' {print $} ' b=$ (($a + 1)) c= ' cat-n $DIR $file|grep $b |awk-f" [<>] ' {print $} ' num=$ (($c + 1) sed-i "" ' $b s#<string> $c </string>#<string> $NUM </string> #g ' $DIR $file else echo "PL Ease use admin "fi
This article is from "for the tribe!" "Blog, be sure to keep this provenance http://10309478.blog.51cto.com/10299478/1725703
About the difference between the apple command sed and CentOS use