0

For example I want to take the content of file named "comment" to be the value of setattr's -v option, something like

cat comment | setfattr -n user.comment -v -  filewanttotaged

but this does not work, neither do

cat comment | xargs setfattr -n user.comment -v - filewantedtotaged

For the latter case, the content is treated as file arugment for setfattr, instead of value of option -v

So how to do this job? Thank you very much!

Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
  • possible duplicate of [Unix - "xargs" - output "in the middle" (not at the end!)](http://stackoverflow.com/questions/1383170/unix-xargs-output-in-the-middle-not-at-the-end) – Chris Maes Jan 06 '15 at 08:53

1 Answers1

2

you can use xargs, but make sure its arguments are not at the end, but after your "-v" option:

cat comment | xargs -i setfattr -n user.comment -v {} filewantedtotaged
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • Thank you! So the key here is to add -i to xargs. – Yi Wang Jan 06 '15 at 09:15
  • Another question is that if there is "\n" in the comment file, only the first line can go into the value of option -v. So there must be some way to tell xargs to escape that end of line, I will check. Do you know how to do this? – Yi Wang Jan 06 '15 at 09:17
  • Yes, add -0 to xargs will do – Yi Wang Jan 06 '15 at 09:21
  • you're welcome... if this answered your question, please accept the answer to mark that the question has been solved. – Chris Maes Jan 06 '15 at 09:48