0

i have this script

#!/bin/bash
MVAR=($(su - git -C "sftp user@xxx.xxx.xxx.xxx << EOF
pwd
EOF
" ))
echo ${MVAR[2]}

the output look like this
Connected to xxx.xxx.xxx.xxx. Remote

how can i modify script to have

Connected to xxx.xxx.xxx.xxx. Remote working directory:

Luthando Ntsekwa
  • 4,192
  • 6
  • 23
  • 52

1 Answers1

0

I think it splits on spaces due to IFS (Internal Field Separator). Try defining IFS to newlines:

$ IFS=$'\n' MVAR=($(su - git -C "sftp user@xxx.xxx.xxx.xxx << EOF
pwd
EOF
" ))

I could make your command work on my machine. I used this one to test locally and get the remote pwd:

$ IFS=$'\n' MVAR=($(sftp -b <(echo pwd) localhost))
$ echo ${abc[1]}
sftp> pwd
$ echo ${abc[2]}                                   
Remote working directory: /home/cbliard
Community
  • 1
  • 1
cbliard
  • 7,051
  • 5
  • 41
  • 47