I am writing a loop which accumulates strings in a variable def, reading from a heredoc. I can't see the value of variable after the loop exits.
#!/usr/bin/sh
def=""
while read x; do
def="$def -D$x"
echo $def
done <<-COMMANDS_GREEN
hello="hello green world"
host="greenmen.com"
port=80
COMMANDS_GREEN
################### exit loop ########################
echo definition: $def
As the script output, inside the loop all. The definition: which is outside the loop doesn't show anything:
-Dhello="hello green world"
-Dhello="hello green world" -Dhost="greenmen.com"
-Dhello="hello green world" -Dhost="greenmen.com" -Dport=80
################### exit loop ########################
definition:
I am writing this under Solaris 10, not bash
Changed to
ksh, it solved the problemthanks to @jhnc and @Gilles Quénot for info provided in comments