1

I try to make a shell script to help me to deploy my api app more easy but below syntax is not valid?

#!/bin/bash

if [ -n "$1" ]
then
  ssh root@10.6.189.9.17 << 'COMMAND'
  cd /var/www/myapp
  git pull
  npm start
  COMMAND
else
  echo "argument is not set!"
fi

I know this is valid

ssh root@10.6.189.9.17 << 'COMMAND'
  cd /var/www/myapp
  git pull
  npm start
  COMMAND

but not after I put them into the condition.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Alisa T Morgan
  • 667
  • 1
  • 7
  • 12
  • 4
    The `COMMAND` word to end the here-doc **must** be the **only** characters on that line -- *no whitespace allowed!* Remove the leading spaces. There is an exception where you can indent with leading tab characters, but they must be tabs not spaces: see https://www.gnu.org/software/bash/manual/bashref.html#Here-Documents – glenn jackman Sep 29 '18 at 11:31
  • @glennjackman many thanks, that's the issue! but I got argument passing problem https://stackoverflow.com/questions/52568684/bash-script-failed-to-pass-argument-in-linux – Alisa T Morgan Sep 29 '18 at 13:11

0 Answers0