Skip to main content
2 of 8
added 5 characters in body
Lawrence
  • 329
  • 1
  • 4
  • 13

How to use the string returned by $() to be used as more than one argument in another command?

My use case:

I need to remove all dev packages listed in composer.json file. Suppose I have two packages: projectx/package-nice and projecty/package-good. To remove them I need to run:

$ composer remove --dev projectx/package-nice projecty/package-good

So I build this command to extract the package list:

echo $(composer show -s | grep -E "^[a-z]+/[0-9a-z_-]+" | awk '{print $1}' | xargs)

This return the list of packages, exacly like this: projectx/package-nice projecty/package-good

So I tried to run the command below, but didn't work because bash is interpreting the return as a single string enclosed by quotes:

$ composer remove --dev $(composer show -s | grep -E "^[a-z]+/[0-9a-z_-]+" | awk '{print $1}' | xargs)

It's the same as:

$ composer remove --dev "projectx/package-nice projecty/package-good"

So, what am I doing wrong?

Thank you.

Lawrence
  • 329
  • 1
  • 4
  • 13