Issue
I try to make a .sh file that list all my no-dev package and then copy them to an other repository. So I come with this code :
#!/bin/sh
list_of_all_no_dev_package=$(composer show --no-dev --name-only)
for no_dev_package in $list_of_all_no_dev_package; do
cp -r "vendor/${no_dev_package}" "${export_path}/vendor/${no_dev_package}"
done
To ensure my cp command is fine, I tried to echo it in my terminal and got something like
cp -r "vendor/mypackage" "myexportpath/vendor/mypackage"
However, if I try to redirect the output to a text file with the >> operator, I got something very different
cp -r "vendor/https://github.com/mypackage/tree/master/whateverfile.php" "myexportpath/vendor/https://github.com/mypackage/tree/master/whateverfile.php
How can I get the first output with a composer command and why are those 2 results so different?
Solution
Problem seems to occur on recent composer installation. It does happend on actual latest : 2.4.1 but does not on 2.1.2
Using composer show --name-only
actually return a result with the full repository path (github or whatever has been set up in the config files) and add 2 ESC char in it. The CLI then prints what's between those 2 ESC char.
Solution is to add the global option --no-ansi
composer show --name-only --no-dev --no-ansi
will return the directory name of the repository in your vendor folder.
Answered By - ViLar Answer Checked By - Clifford M. (WPSolving Volunteer)