Search code examples
windowscommand-linecommand-prompt

How to write a multiline command?


How do we extend a command to the next line?

Basically what's the Windows alternative for Linux's:

ls -l \
/usr/

Here we use backslashes to extend the command onto the next lines.

What's the equivalent for Windows?


Solution

  • Solution 1 In CMD, Use ^ , example

    docker run -dp 3000:3000 ^
      -w /app -v "$(pwd):/app" ^
      --network todo-app ^
      -e MYSQL_HOST=mysql ^
      -e MYSQL_USER=root ^
      -e MYSQL_PASSWORD=secret ^
      -e MYSQL_DB=todos ^
      node:12-alpine ^
      cmd "npm install && yarn run start"
    

    Solution 2 In PowerShell, Use ` (backtick) , Example

    docker run -dp 3000:3000 `
      -w /app -v "$(pwd):/app" `
      --network todo-app `
      -e MYSQL_HOST=mysql `
      -e MYSQL_USER=root `
      -e MYSQL_PASSWORD=secret `
      -e MYSQL_DB=todos `
      node:12-alpine `
      cmd "npm install && npm run start"