开发者

How does this complicated shell command (containing |, && and sed) work?

开发者 https://www.devze.com 2022-12-19 19:03 出处:网络
I\'m trying to figure out how to work git filter-branch and I need help with some basic Linux scripting commands.

I'm trying to figure out how to work git filter-branch and I need help with some basic Linux scripting commands.

'git ls-files -s | sed "s-\t-&newsubdir/-" |
                GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                        git update-index --index-info &&
         mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

Can anyone break this down for me and explain each part?

I'm most interested in the '|' notation, the && notation, and the sed command.开发者_如何转开发


| connects stdout of the preceding command to stdin of the following command.

&& executes the following command if the return code of the preceding command is 0 (that is, the command succeeded).

The s command in sed is a substitution. It searches for a regex match for the first argument and replaces it with the second. The argument separator is traditionally /, but it will use the first character that follows, - in this case. The & in the replacement is replaced with the entire match.


"|" is the unix pipe command which connects the command on the left sides output to the command on the right side's input.

"&&" is the unix "and" command which will execute the command on its right if and only if the command on it's left completes successfully

"sed" is the unix "stream editor" a powerful editing tool which parses and edits it's input

0

精彩评论

暂无评论...
验证码 换一张
取 消