function _drush_escapeshellarg_linux

8.0.x _drush_escapeshellarg_linux($arg, $raw = FALSE)
6.x _drush_escapeshellarg_linux($arg)
7.x _drush_escapeshellarg_linux($arg, $raw = FALSE)
5.x _drush_escapeshellarg_linux($arg)
master _drush_escapeshellarg_linux($arg, $raw = FALSE)

Linux version of escapeshellarg().

This is intended to work the same way that escapeshellarg() does on Linux. If we need to escape a string that will be used remotely on a Linux system, then we need our own implementation of escapeshellarg, because the Windows version behaves differently.

1 call to _drush_escapeshellarg_linux()


includes/, line 156
Functions used when Drush is starting up.


function _drush_escapeshellarg_linux($arg, $raw = FALSE) {
  // For single quotes existing in the string, we will "exit"
  // single-quote mode, add a \' and then "re-enter"
  // single-quote mode.  The result of this is that
  // 'quote' becomes '\''quote'\''
  $arg = preg_replace('/\'/', '\'\\\'\'', $arg);

  // Replace "\t", "\n", "\r", "\0", "\x0B" with a whitespace.
  // Note that this replacement makes Drush's escapeshellarg work differently
  // than the built-in escapeshellarg in PHP on Linux, as these characters
  // usually are NOT replaced. However, this was done deliberately to be more
  // conservative when running _drush_escapeshellarg_linux on Windows
  // (this can happen when generating a command to run on a remote Linux server.)
  $arg = str_replace(array("\t", "\n", "\r", "\0", "\x0B"), ' ', $arg);

  // Only wrap with quotes when needed.
  if (!$raw) {
    // Add surrounding quotes.
    $arg = "'" . $arg . "'";

  return $arg;