Search code examples
linuxbashzshinfluxdbinfluxdb-2

Zsh bad substitution error when installing Influxdb2.0


I am following the installation instructions from this article but I get a bad substitution error from zsh when executing this command:

export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)
echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null

What am I supposed to change for zsh?


Solution

  • ${DISTRIB_ID,,} is a Bash-specific parameter expansion to lowercase the value of the variable.

    https://askubuntu.com/a/383360/25077 suggests ${(L)DISTRIB_ID} as a corresponding operation in Zsh.

    But there is no real reason for this to use any constructs specific to either shell; the operation is simple to do portably in POSIX sh too (albeit at the cost of an external process).

    For what it's worth, unless there are other reasons you need to, the export statements here are unnecessary, too. See also Correct Bash and shell script variable capitalization

    distrib_id=$(lsb_release -si | tr A-Z a-z)
    distrib_codename=$(lsb_release -sc)
    echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/$distrib_id $distrib_codename stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null