Ignore empty results for xargs in Mac OS X

前端 未结 4 1996
迷失自我
迷失自我 2021-02-07 10:36

The code for my website uses this piece of code for automatic deployment on the server (Ubuntu).

cmd = \'cd \' + checkout_dir + \' && \' +

4条回答
  •  情话喂你
    2021-02-07 11:27

    The -r for xargs isn't working on OS X, since it's a GNU extension. As for workaround, you should specify some dummy file which can be parsed by xargs or to not call command when there are no arguments (which can be checked before).

    Method using temporary file (or any other placeholder):

    some_cmd ... | xargs svn revert $(mktemp)
    

    Using condition in shell:

    files=$(cd checkout_dir && ... | tac)
    if [ -n "$files" ]; then
        echo $files | xargs && ...
    fi
    

    See also: Ignore empty result for xargs

提交回复
热议问题