Setting up a prompt in bash

I’m setting up programs.bash and in the initExtra I got
initExtra = ‘’
h2d() {
echo “ibase=16; $@”|bc

  complete -cf sudo

  COLOR1=$(xrdb -query | awk '/prompt.color1/ { print substr($2,2) }')
  qq=';2;'$( h2d ${COLOR1:0:2} )';'$( h2d ${COLOR1:2:2} )';'$( h2d ${COLOR1:4:2} )'m\]'
  export PS1="\n  ${COLOR1}\u${NC}${COLOR2}\h: ${NC}\W ${COLOR2}]${NC} "

When it gets to the export PS1, it says “undefined variable COLOR1” All this “code” has been working forever in my regular .bashrc.

You have to escape the ${.

As you are in an intended string, you have to write ''${ where you want to have ${ in the generated bash script.