would output 1. So, passing $db_name to validate unquoted makes it validate only the first word.
Second, in validate you must be trying to count words, not lines. But you split lines after you count them, which makes no sense. The correct incantation would be:
if [ `echo "$i" | wc -w` != 1 ]; then # not one word
Third, judging from the link from the original post (can’t duplicate it here), spaces are allowed in database names.
$ db_name=d1 && cmd="create database ${db_name@Q}" && echo "$cmd" && influx -execute "$cmd"
create database 'd1'
ERR: error parsing query: found d1, expected identifier at line 1, char 16
Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use <database>".
error parsing query: found d1, expected identifier at line 1, char 16
From what I gather, ${...@Q} always returns single quoted string, and the only replacement it makes is ' -> '\''. Can it really help?
#/usr/bin/env zsh
set -xe
DB_NAME=$1
influx -execute "CREATE DATABASE ${(qqq)DB_NAME:-q}"
Tested on command line with:
$ zsh main.sh 'my new database "name" is weird'
+main.sh:3> DB_NAME='my new database "name" is weird'
+main.sh:5> influx -execute 'CREATE DATABASE "my new database \"name\" is weird"'