For example, i have a key list in file named keys, and some key name contains blank:
keya
keyb
"a blank key"
I want to get values from redis in bash, so my command is:
while read key ;do redis-cli -h 127.0.0.1 get $key;done < keys
But when the name contains blank, the comand executes failed:
none
none
(error) ERR wrong number of arguments for 'type' command
Does anynoe knows how to fix this? Thanks very much.
while ...; do [[ -z "$key" ]] && continue ; redis ...; done< keysuse< <(grep -v '^$' keys)$key, because the quotes from your data file are literal, quotes inside your source code are syntax, and the two don't substitute for each other. Take them out of"a blank key"-- the line should be justa blank key-- and then make itget "$key", notget $key.