I have a bash script, the file name is deploy.sh so in my terminal I do
#!/bin/bash
if [ -n "$1" ]
then
  ssh root@101.181.42.10 << 'COMMAND'
    cd /var/www/myApp
    git pull
    npm i
    pm2 kill
    pm2 start pm2.json --env $1
COMMAND
else
  echo "argument is not set!"
fi
but I got this error error: option--env ' argument missing` which means $1 is not set, I wonder why, I tried this in my terminal
. deploy staging
then my bash I have
if [ -n "$1" ]
then
  ssh root@101.181.42.10 << 'COMMAND'
    echo $1
COMMAND
else
  echo "argument is not set!"
fi
I can see 'staging' been print. Am I concat the argument wrongly in my command?
 
    