我正在写一个循环,它在变量
def
中累积字符串,从 heredoc 读取。循环退出后我看不到变量的值。
#!/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
作为脚本输出,在循环里面全部。循环外的定义:不显示任何内容:
-Dhello="hello green world"
-Dhello="hello green world" -Dhost="greenmen.com"
-Dhello="hello green world" -Dhost="greenmen.com" -Dport=80
################### exit loop ########################
definition:
我在 Solaris 10 下写这篇文章,而不是 bash