My goal is to write an as simple as possible (but not more simple) that generates a list of currently installed PHP extensions (*.so files) that the user can simply copy/paste into their php.ini. It should be compatible at minimum with OS X and at least some major Linux distros (Ubuntu, Arch Linux, RHEL, etc.).
The expected output would look like:
extension=iconv.so extension=mcrypt.so ...
So far, I have come up with this:
find `php-config --extension-dir` -name "*.so" | rev | cut -d / -f 1 | rev
It works well, but I feel it's a bit clumsy with all the string reversions. And, it only generates the extensions' names, it does not add the
I needed to use the reversions because the extension-dir might be of any depth, thus I cannot simply cut the string at a pre-determined path separator position. However, I know that if I cut it from the end at the first separator, I will get only the filename.
Then I discovered the
replace utility and wrote this, which is a perfect fit for my task, except it does not seem to be available on OS X and Arch Linux, the two systems I use most:
find `php-config --extension-dir` -name "*.so" | replace `php-config --extension-dir`/ 'extension='
Basically, I am looking for other creative (but simple) ways of completing this task. What other utilities could I use? Educate me! :)