1

I want to form an argument for tail using xargs.

"string" | xargs -I '{}' tail -F *{}*

This results in tail "*{}*" which does not work. How do I remove the quotes and turn it into a valid argument for tail? i.e. tail *string*

4
  • 1
    Doesn't "string" | result in a bash: string: command not found error? Do you have a command named string? This results in How do you know? How did you check that it results in that? How do I remove the quotes Who added the qoutes? How were they added? turn it into a valid argument for tail? Is "*{}*" and invalid argument? Do you really have a filename named literally *string* that you want tail from? Or do you expect *string* to expand to list of filenames that match the globulation pattern? which does not work Is there an error message? Commented May 27, 2020 at 21:43
  • @manu190466 I suspect that * symbols in your comment have been interpreted as markup - please can you check the formatting (e.g. putting the code inside backticks). Commented May 27, 2020 at 22:05
  • Maybe what you want is : echo "string" | xargs -I '{}' tail -F {} Commented May 27, 2020 at 22:08
  • @alaniwi thank you for your comment, I actually had problems with my formatting Commented May 27, 2020 at 22:10

1 Answer 1

1

* is interpreted by Bourne shell (pathname expansion) at the moment your command is parsed, before it is actually executed, NOT at the moment tail is executed.

If you want that the command built by xargs be subject to bash's pathname expansion, you need to execute bash:

echo "string" | xargs -I '{}' bash -c "tail -F *'{}'*"

Security issue: if you don't have control over the file names sent to xargs, then with specially crafted filenames, you may end up inadvertently executing hamrful commands.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.