> On Thursday, October 4, 2012 2:36:07 PM UTC-5, Greg Martin wrote:
>> Is there a way to expand new lines in heredocs?
>> In the script below "echo $all" prints:
>> put File1
>> put File2
>> ...
>> however $all in the heredoc DATA expands to
>> put FILE1\nput FILE2\nput ...
>> ###########################
>> #!/bin/sh
>> FILE_LIST="
>> File1
>> File2
>> File3
>> File4
>> File5
>> "
>> nl="\n"
>> for each in $FILE_LIST
>> do
>> all=$all"put "$each${nl}
>> done
>> echo $all
>> stty -echo
>> read -p "Password: " pass; echo
>> stty echo
>> export SSHPASS=$pass
>> sshpass -e sftp -oBatchMode=no -b - user@address <<DATA
>> cd /home/dev/www
>> $all
>> bye
>> DATA
> Two changes should help:
> use the special dollar-single-quote form:
> nl=$'\n'
> and
> use quoting:
> echo "$all"
> Also, you can suppress character output during read for passwords without using stty by doing using -s (and you should almost always use -r):
> read -s -r -p "Password: " pass
> Change your shebang to specify Bash:
> #!/bin/bash
> because on many systems /bin/sh is not a symlink to Bash.
Thanks for your help Dennis. That solved it.