1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

macでのxargsの扱い

Posted at

svnのコマンドをワンライナーで実現したい

ドキュメント管理でsvnを使用しています。
更新されたドキュメントは問題無いのですが、新規追加や削除したドキュメントは svn add や svn del をドキュメント毎に実施する必要があります。
ある程度のファイル数がある場合、結構手間なのでワンライナーで処理しコマンドを alias に登録しようと思いました。

linuxの場合

こんな感じで問題無く実現できました。

> svn status | grep '^?' | sed -e 's/\?[ ]*//g' | xargs -i svn add {}

macの場合

xargs に -i のオプションが無いので同じコマンドを実行出来ません。
man を確認し255バイトの制約は今は気にしないとして、-I オプションで対応することにしました。

❯ svn status | grep '^?' | sed -e 's/\?[ ]*//g' | xargs -I{} echo svn add {}
svn add path1/path2/aaa.doc
svn add path1/path3/bbb.doc

echo で確認すると上手くいきそうな雰囲気だったので、実際に実行して見ます。

❯ svn status | grep '^?' | sed -e 's/\?[ ]*//g' | xargs -I {} svn add {}     
xargs: svn: No such file or directory

なるほど、svn が見つからない…か…
でもパイプの最初にある svn status は実行出来ているし path は通っている…
"svn add path1/path2/aaa.doc" を1つのコマンドとして送っている??
であれば、 echo も同じようにエラーになるはずだし 「svn: No such file or directory」 こういうエラーにはならないはず…
という事は、本当に svn が見つからないのかな?

❯ svn status | grep '^?' | sed -e 's/\?[ ]*//g' | xargs -I{} /opt/local/bin/svn add {}
A  (bin)  path1/path2/aaa.doc
A  (bin)  path1/path3/bbb.doc

できた。
ちょっと本質的な部分を理解できていないので、本当はもう少しスマートな対応方法があるかもしれません。
mac での環境は linux と何か違うのかとか。

ちょっと手抜きですが、今回はこの対応としておきます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?