I'm doing the following assignment in my bash script but keep receiving weird errors when not doing it inline.
Original that works
$DB_ENV = $(echo "$(cat .dbenv)" | tr '\n' ' ')
echo "CACERT=\"$(cat .cacert)\" $DB_ENV" yarn run knex migrate:up | bash -
New that doesn't
#!/bin/bash
$DB_ENV=$(echo $(cat .env) | tr '\n' ' ')
$CACERT="CACERT=\"$(cat .cacert)\""
if [[ $1 != 'up' && $1 != 'down' ]]; then
echo Available subcommands are "up" and "down"
else
echo "$CACERT $DB_ENV yarn run knex migrate:$1" | bash -
fi
For some reason, on the first variable assignment line I'm getting
migrate.sh: line 3: =NODE_ENV="production": command not found
and on the second
migrate.sh: line 4: =CACERT="<file contents with newlines>": File name too long
Genuinely confused as to why this is happening, any help would be great!