문제

I'm trying to loop over all environment variables in a shell script, and create an HTML query string from ones which match a pattern. Unfortunately, I can't seem to assign to variables in the loop. I've got this:

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

But this gives me

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

How do I fix this?

도움이 되었습니까?

해결책

In the assignment, remove space between variable name and =

TAGS="${TAGS}${item}"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top