In a bash script I set a command this way:
getdblist_cmd=(sudo -u $backup_user $psql -p $pgsql_port -U $pgsql_user -d postgres -q -t -c 'SELECT datname from pg_database')
Then I run it with
dblist=`${getdblist_cmd[@]}`
I don't get any error into the bash script but the $dblist
variable is empty.
How can I execute that command and put its output into a variable?
dblist=`"${getdblist_cmd[@]}"`
^ ^
The [@]
operator works only correct if the ${...}
is surrounded by quotes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.