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.

Related topics

1 call 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.

File

includes/exec.inc, line 352
Functions for executing system commands. (e.g. exec(), system(), ...).

Code

function _drush_escapeshellarg_linux($arg) {
  // 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);

  // Add surrounding quotes.
  $arg = "'" . $arg . "'";

  return $arg;
}