Concatenate multiple shell commands via logical implication ( && )
@return Shell The concatenated shell command
420345
public static function sequence(...$items){
        $cmd = [];
        foreach ($items as $item) {
            $cmd[] = ($item instanceof static)?$item->getShellCommand():$item;
        }
        return new static(implode(' && ',$cmd));
    }
475887
protected function buildCommand()
    {

        // Log
        $this->log('Command building started ', $this->loglevel);

        // Building the executable
        $this->realCommand = (string) $this->commandline;

        $this->additionalCmds = '';

        // Adding the source filename at the end of command, validating the existing
        // sourcefile position explicit mentioning
        if ($this->addsourcefile === true) {
            $this->realCommand .= ' ' . self::SOURCEFILE_ID;
        }

        // Setting command output redirection with content appending
        if ($this->output !== null) {
            $this->additionalCmds .= sprintf(
                ' 1>%s %s',
                $this->appendoutput ? '>' : '',
                escapeshellarg($this->output->getPath())
            );
        } elseif ($this->spawn) { // Validating the 'spawn' configuration, and redirecting the output to 'null'
            $this->additionalCmds .= sprintf(' %s', 'WIN' === $this->osvariant ? '> NUL' : '1>/dev/null');

            $this->log("For process spawning, setting Output nullification ", $this->loglevel);
        }

        // Setting command error redirection with content appending
        if ($this->error !== null) {
            $this->additionalCmds .= sprintf(
                ' 2>%s %s',
                $this->appendoutput ? '>' : '',
                escapeshellarg($this->error->getPath())
            );
        }

        // Setting the execution as a background process
        if ($this->spawn) {
            // Validating the O.S. variant
            if ('WIN' === $this->osvariant) {
                $this->additionalCmds = 'start /b ' . $this->additionalCmds; // MS Windows background process forking
            } else {
                $this->additionalCmds .= ' &'; // GNU/Linux background process forking
            }
        }

        $this->additionalCmds = rtrim($this->additionalCmds);

        // Log
        $this->log('Command built : ' . $this->realCommand . $this->additionalCmds, $this->loglevel);

        // Log
        $this->log('Command building completed ', $this->loglevel);
    }
1349382
public static function merge()
    {
        $args = func_get_args();
        $where = array();
        $options = array();
        foreach ($args as $o) {
            $options = array_merge($options, $o);
            if (isset($o['where'])) {
                if (count($where) === 0) {
                    $where = $o['where'];
                } else {
                    foreach ($o['where'] as $oc) {
                        $matches = 0;
                        foreach ($where as $wc) {
                            if ($oc == $wc) {
                                $matches += 1;
                            }
                        }
                        if ($matches === 0) {
                            $where[] = $oc;
                        }
                    }
                }
            }
        }
        $options['where'] = $where;
        return $options;
    }
923243
public function buildCommand()
	{
		$output = ProcessUtils::escapeArgument( $this->output );
		$redirect = $this->shouldAppendOutput ? ' >> ' : ' > ';
		if ( $this->withoutOverlapping )
		{
			if ( windows_os() )
			{
				$command = '(echo \'\' > "' . $this->mutexPath() . '" & ' . $this->command . ' & del "' . $this->mutexPath() . '")' . $redirect . $output . ' 2>&1 &';
			}
			else
			{
				$command = '(touch ' . $this->mutexPath() . '; ' . $this->command . '; rm ' . $this->mutexPath() . ')' . $redirect . $output . ' 2>&1 &';
			}
		}
		else
		{
			$command = $this->command . $redirect . $output . ' 2>&1 &';
		}

		return $this->user && !windows_os() ? 'sudo -u ' . $this->user . ' -- sh -c \'' . $command . '\'' : $command;
	}
1152143
def exec(*commands)
      ret = ''
      commands.each { |cmd| ret += shell.exec(cmd) }
      ret + shell.exec('exec')
    end
617770
public function concat() {
		$value = $this->value;
		for ( $i = 0; $i < func_num_args(); $i ++ ) {
			$value .= (string) func_get_arg( $i );
		}

		return new GString( $value );
	}
572036
public function buildCommand()
	{
		if ($this->withoutOverlapping)
		{
			$command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().') > '.$this->output.' 2>&1 &';
		}
		else
		{
			$command = $this->command.' > '.$this->output.' 2>&1 &';
		}


		return $this->user ? 'sudo -u '.$this->user.' '.$command : $command;
	}
1036663
private String[] augmentCommand(String[] args, Class<? extends Command> cmd,
			boolean acceptsInputFile) {
		OptionGroup<ID> options;
		try {
			if (acceptsInputFile) {
				options = OptionIntrospector.introspect(cmd, InputFileCommand.class);
			} else {
				options = OptionIntrospector.introspect(cmd);
			}
		} catch (IntrospectionException e) {
			//should never happen
			throw new RuntimeException(e);
		}
		
		ShellContext sc = ShellContext.current();
		for (Option<ID> o : options.getOptions()) {
			if (o.getLongName().equals("style")) {
				args = ArrayUtils.add(args, "--style");
				args = ArrayUtils.add(args, sc.getStyle());
			} else if (o.getLongName().equals("locale")) {
				args = ArrayUtils.add(args, "--locale");
				args = ArrayUtils.add(args, sc.getLocale());
			} else if (o.getLongName().equals("format")) {
				args = ArrayUtils.add(args, "--format");
				args = ArrayUtils.add(args, sc.getFormat());
			} else if (o.getLongName().equals("input") &&
					sc.getInputFile() != null && !sc.getInputFile().isEmpty()) {
				args = ArrayUtils.add(args, "--input");
				args = ArrayUtils.add(args, sc.getInputFile());
			}
		}
		
		return args;
	}
531329
private static String[] executeShellCommand(String[] command)
  throws IOException {
    String groups = Shell.execCommand(command);
    StringTokenizer tokenizer = new StringTokenizer(groups);
    int numOfTokens = tokenizer.countTokens();
    String[] tokens = new String[numOfTokens];
    for (int i=0; tokenizer.hasMoreTokens(); i++) {
      tokens[i] = tokenizer.nextToken();
    }

    return tokens;
  }
1047763
public function getCommandToExecute()
    {
        $command = implode(
            " ",
            array(
                $this->bin,
                $this->script,
                $this->command,
            )
        );
        return trim(preg_replace('/\s+/', ' ', $command));
    }
746869
private function createFromCommand()
    {
        $command = BranchCommand::getInstance($this->getRepository())->listBranches();
        $outputLines = $this->repository->getCaller()->execute($command)->getOutputLines(true);
        foreach ($outputLines as $outputLine) {
            $matches = static::getMatches($outputLine);

            if ($this->name === $matches[1]) {
                $this->parseOutputLine($outputLine);

                return;
            }
        }

        throw new InvalidBranchNameException(sprintf('The %s branch doesn\'t exists', $this->name));
    }
1050675
public function getCommands()
    {
        foreach ($this->commands as $command) {
            if ($command instanceof \Traversable) {
                //Nested commands
                yield from $command;
            }

            yield $command;
        }
    }
752818
private function getCLISubjects()
    {
        $command = '';
        if (!is_null($this->commandSubject)) {
            $command .= ' ';
            if ($this->commandSubject instanceof SubCommandCommand) {
                $command .= $this->commandSubject->getCommand();
            } else {
                if (is_array($this->commandSubject)) {
                    $command .= implode(' ', array_map('escapeshellarg', $this->commandSubject));
                } else {
                    $command .= escapeshellarg($this->commandSubject);
                }
            }
        }
        if (!is_null($this->commandSubject2)) {
            $command .= ' ';
            if ($this->commandSubject2 instanceof SubCommandCommand) {
                $command .= $this->commandSubject2->getCommand();
            } else {
                if (is_array($this->commandSubject2)) {
                    $command .= implode(' ', array_map('escapeshellarg', $this->commandSubject2));
                } else {
                    $command .= escapeshellarg($this->commandSubject2);
                }
            }
        }
        return $command;
    }
342299
public function enableCommandName()
    {
        if (!$this->commandNameEnabled
            && $this->commandName
            && isset($this->arguments[0])
            && $this->arguments[0] === $this->commandName
        ) {
            unset($this->arguments[0]);
            $this->arguments = array_values($this->arguments);
        }
        $this->commandNameEnabled = true;
        return $this;
    }
814431
private function formatCommand()
    {
        $cmdGroup = [];
        $noGroup = [];
        foreach ($this->console->getCommands() as $name => $class) {
            if ($class !== __CLASS__) {
                $class = new \ReflectionClass($class);
                $property = $class->getDefaultProperties();
                $property = isset($property['description']) ? $property['description'] : '';

                $hadGroup = strpos($name, ':');
                $group = substr($name, 0, $hadGroup);
                $name = Colour::colour($name, Colour::GREEN);
                $this->commandLength > strlen($name) || $this->commandLength = strlen($name) + 3;

                if ($hadGroup) {
                    $cmdGroup[$group][$name] = $property;
                } else {
                    $noGroup[$name] = $property;
                }
            }
        }
        return [$noGroup, $cmdGroup];
    }
789428
private function doAddCommands()
    {
        if (!empty($this->newCommands)) {
            $this->shell->addCommands($this->newCommands);
            $this->newCommands = [];
        }
    }
1369860
public function getProcess()
    {
        if (0 === count($this->prefix) && 0 === count($this->arguments)) {
            throw new LogicException('You must add() command arguments before calling getProcess().');
        }

        $options = $this->options;

        $arguments = array_merge($this->prefix, $this->arguments);
        $script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));

        if ($this->inheritEnv) {
            $env = array_replace($_ENV, $_SERVER, $this->env);
        } else {
            $env = $this->env;
        }

        $process = new Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);

        if ($this->outputDisabled) {
            $process->disableOutput();
        }

        return $process;
    }