function _drush_escapeshellarg_linux

8.0.x startup.inc _drush_escapeshellarg_linux($arg, $raw = FALSE)
6.x exec.inc _drush_escapeshellarg_linux($arg)
7.x exec.inc _drush_escapeshellarg_linux($arg, $raw = FALSE)
5.x exec.inc _drush_escapeshellarg_linux($arg)
master startup.inc _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.

2 calls to _drush_escapeshellarg_linux()
drush_escapeshellarg in includes/exec.inc
Platform-dependent version of escapeshellarg(). Given the target platform, return an appropriately-escaped string. The target platform may be omitted for args that are /known/ to be for the local machine. Use raw to get an unquoted version of the…
drush_startup in includes/startup.inc
drush_startup is called once, by the Drush "finder" script -- the "drush" script at the Drush root. It finds the correct Drush "wrapper" or "launcher" script to use, and executes it with process replacement.

File

includes/startup.inc, line 97
Functions used when Drush is starting up.

Code

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;
}