#!/usr/bin/env php /dev/null|grep -Po '^user.LOCATIONS=\"\K[^\\\"]+'")); if (!empty($realdisk)) { // there may be several disks participating in this path (e.g. disk1,2,3) so // only return the first disk and replace 'user' with say 'cache' or 'disk1' $replacement = str_replace('/mnt/user/', '/mnt/'.strtok($realdisk.',', ',').'/', $match[0]); if (is_file($replacement)) { // the replacement path (e.g. /mnt/disk1/domains/vmname/vdisk1.img) checks out so use it return $replacement; } } } return $match[0]; }, $arg); }; array_shift($argv); array_walk($argv, 'detect_user_share'); $whole_cmd = ''; foreach ($argv as $arg) { $whole_cmd .= escapeshellarg($arg).' '; } echo trim($whole_cmd);