在shell脚本循环中追加变量

时间:2014-04-29 14:59:57

标签: shell sh

我试图在shell脚本中循环遍历所有环境变量,并从匹配模式的字符串创建HTML查询字符串。不幸的是,我似乎无法在循环中分配变量。我有这个:

#!/bin/sh
IFS=$'\n'
TAGS=""
for item in $(printenv)
do
   if [[ $item == FOO_TAG_* ]]
   then
       TAGS = "${TAGS}&${item}"
   fi
done

但是这给了我

/etc/script.sh: line 9: TAGS: command not found
/etc/script.sh: line 9: TAGS: command not found

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

在赋值中,删除变量名和=

之间的空格
TAGS="${TAGS}${item}"
相关问题