Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NL in Heredoc

25 views
Skip to first unread message

Greg Martin

unread,
Oct 4, 2012, 3:36:06 PM10/4/12
to
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

DennisW

unread,
Oct 5, 2012, 8:55:04 AM10/5/12
to
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.

Greg Martin

unread,
Oct 5, 2012, 11:35:44 AM10/5/12
to
Thanks for your help Dennis. That solved it.

0 new messages