vendredi 27 février 2015

Why does the input to xargs is 1 string but without is strings in separate line?


I am trying to pipe file to rm via xargs. I understand that what I am tryng to do could be done by git clean but I am practicing the cli.

I tried this:



for files in $(git status --porcelain| sed 's/^??//g'); do echo $files; done | xargs rm -rf


but it did not work. I figured it was because when running this:



for files in $(git status --porcelain| sed 's/^??//g'); do echo $files; done | xargs


The files seem to be in 1 string separated by a space.

But when I run for files in $(git status --porcelain| sed 's/^??//g'); do echo -n $files; done the files are displayed in the console in a separate line.


So (if I am right on this) what is the difference between:

for files in $(git status --porcelain| sed 's/^??//g'); do echo -n $files; done | xargs

and


for files in $(git status --porcelain| sed 's/^??//g'); do echo -n $files; done


and the files in the second case are displayed each in each own line and in the first case it is one string? And how would I fix this so that it works with rm -rf?



Aucun commentaire:

Enregistrer un commentaire