【发布时间】:2017-02-08 21:38:31
【问题描述】:
我正在尝试将一些 php 变量的值放入 bash 脚本中,以便设置其他 bash 变量。基本上我需要能够访问变量的值 - 变量名。
脚本可以找到并读取文件,找到 php 变量,但是当我尝试设置它们时它只是挂起。这是我所拥有的:
variables=(database_user database_password dbase);
paths=(modx_core_path modx_connectors_path modx_manager_path modx_base_path);
for index in "${variables[@]}"; do
index=\$$index
echo $index;
$index="$(grep -oE '\$${!index} = .*;' $config | tail -1 | sed 's/$${!index} = //g;s/;//g')";
done
不知道我在这里做错了什么......
【问题讨论】:
-
@123,请不要建议ABS作为参考;它因展示不良做法而臭名昭著。 BashFAQ #6 是对间接变量的更新和积极维护的讨论。