0

I'm attempting to run a sequence of commands over SSH. This answer inspired me to use EOF which seemed to work fine at first, but started acting up once I tried running subshell commands using $().

Anyone understand why this:

#!/bin/bash

ssh -o StrictHostKeyChecking=no -tt abcdef@zxcv.net << EOF
    cd "$(ls -td -- ~/www/builds/* | head -n 1)"
    pwd
    composer install
    npm run installation
    npm run clean 
    npm run build 
    exit
EOF

Does this?

17-May-2019 10:29:26    Last login: Fri May 17 12:28:44 2019 from 82.148.198.138
17-May-2019 10:29:26    
17-May-2019 10:29:26        cd ""
17-May-2019 10:29:26        pwd
17-May-2019 10:29:26        composer install
17-May-2019 10:29:26        npm run installation
17-May-2019 10:29:26        npm run clean
17-May-2019 10:29:26        npm run build
17-May-2019 10:29:26        exit

The subshell returns blank when executed from a shell script, but works fine when executing it manually in a bash terminal. This happens without the double quotes as well.

I'm doing this on a Ubuntu server.

Ben
  • 561
  • 1
  • 5
  • 17
  • 2
    The subshell is expanded on your local machine rather than by the remote shell. Put your delimiter (EOF) in quotes (more info [here](https://stackoverflow.com/questions/4937792/using-variables-inside-a-bash-heredoc)) – Aaron May 17 '19 at 11:45
  • 1
    Quick fix: Change `<< EOF` into `<< 'EOF'` – KamilCuk May 17 '19 at 12:00

0 Answers0