开发者

pipelines vs for

Starting to play with bash on Linux, I am trying to perform a clearcase operation on all files resulting from an other clearcase operation. In other words I want to check in all the checked out files.

The command to list checked out files is: cleartool lsco -short -rec. The command to check in a file is: cleartool ci -nc filename.

I am able to do that using the following for loop:

for f in 'cleartool  lsco -short -rec.'; do cleartool ci -nc $f; done

I am wondering if there开发者_JAVA百科 is an other way to do that using pipelines? Something like:

cleartool lsco -short -rec . | cleartool ci -nc

The problem here is that cleartool doesn't read stdin but expects a parameter, correct?


Yes, correct.

In general, you can convert "list of arguments one per line, as coming through a pipe" to "list of arguments all in the same line, as in a command invocation" using xargs:

Richard also points out a way to do this more directly using shell substitution.

$ cleartool lsco -short -rec . | xargs cleartool ci -nc


cleartool ci -nc `cleartool lsco -short -rec .`


I have these two functions defined in my .bashrc:

$ cico () { ct lsco -me -cview -short ${@} | enquote | xargs cleartool ci -nc; }
$ cicor () { ct lsco -me -r -cview -short ${@} | enquote | xargs cleartool ci -nc; }

Enquote is:

$ enquote () { /usr/bin/sed 's/^/"/;s/$/"/' ; }

You'll want the -me and -cview if you start working on a project with other people, because, by default, lsco will show everyone's checked out files and the files you have checked out to different views.

In general, the main command you're looking for is xargs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜