title: How to pass a target argument in a sh script to run Docker build for a specific environment
body: <p>I'm building a <code>sh</code> script to be able to run Docker containers all in once. In this way, I no need to run single containers every time.
  What I need to add now is a way to run my <code>docker-compose up --build -target=&lt;ENV&gt;</code> the ENV will be DEV or PROD. In this way, I can run the right environment in my Docker setup.</p>
  <p>At this time my script looks as follow but when I try to pass <code>$2 = $DEV</code> is giving me an error of <code>[: =: unary operator expected</code> and I don't know what could be the right fix to this</p>
  <pre><code>#!/bin/bash
  
  CLEAN=&quot;clean&quot;
  RUN=&quot;run&quot;
  STOP=&quot;stop&quot;
  DEV=&quot;dev&quot;
  PROD=&quot;prod&quot;
  
  if [ &quot;$#&quot; -eq 0 ] || [ $1 = &quot;-h&quot; ] || [ $1 = &quot;--help&quot; ]; then
      echo &quot;Usage: ./myapp [OPTIONS] COMMAND [arg...]&quot;
      echo &quot;       ./myapp [ -h | --help ]&quot;
      echo &quot;&quot;
      echo &quot;Options:&quot;
      echo &quot;  -h, --help    Prints usage.&quot;
      echo &quot;&quot;
      echo &quot;Commands:&quot;
      echo &quot;  $CLEAN      - Stop and Remove containers.&quot;
      echo &quot;  $RUN        - Build and Run containers.&quot;
      echo &quot;  $STOP       - Stop containers.&quot;
      exit
  fi
  
  clean() {
      stop_existing
      remove_stopped_containers
      remove_unused_volumes
  }
  
  run() {
      echo &quot;Cleaning...&quot;
      clean
  
      echo &quot;Running docker...&quot;
          if [ $2 = $DEV ]; then
              echo &quot;$DEV - Running in - $DEV - environment&quot;
              docker-compose up --build -target=$DEV
          fi
  
  }
  
  stop_existing() {
      MYAPP=&quot;$(docker ps --all --quiet --filter=name=wetaxitask_api_dev)&quot;
      REDIS=&quot;$(docker ps --all --quiet --filter=name=wetaxitask_redis)&quot;
      MONGO=&quot;$(docker ps --all --quiet --filter=name=wetaxitask_mongodb)&quot;
  
      if [ -n &quot;$MYAPP&quot; ]; then
          docker stop $MYAPP
      fi
  
      if [ -n &quot;$REDIS&quot; ]; then
          docker stop $REDIS
      fi
  
      if [ -n &quot;$MONGO&quot; ]; then
          docker stop $MONGO
      fi
  }
  
  remove_stopped_containers() {
      CONTAINERS=&quot;$(docker ps -a -f status=exited -q)&quot;
      if [ ${#CONTAINERS} -gt 0 ]; then
          echo &quot;Removing all stopped containers.&quot;
          docker rm $CONTAINERS
      else
          echo &quot;There are no stopped containers to be removed.&quot;
      fi
  }
  
  remove_unused_volumes() {
      CONTAINERS=&quot;$(docker volume ls -qf dangling=true)&quot;
      if [ ${#CONTAINERS} -gt 0 ]; then
          echo &quot;Removing all unused volumes.&quot;
          docker volume rm $CONTAINERS
      else
          echo &quot;There are no unused volumes to be removed.&quot;
      fi
  }
  
  if [ $1 = $CLEAN ]; then
      echo &quot;Cleaning...&quot;
      clean
      exit
  fi
  
  if [ $1 = $RUN ]; then
      run
      exit
  fi
  
  if [ $1 = $STOP ]; then
      stop_existing
      exit
  fi
  </code></pre>
  <p>What I want to achieve is that possible to run my sh as follow</p>
  <pre><code>./script.sh run dev or prod
    
  </code></pre>