如何分配名称存储在bash中另一个变量中的变量?像(例子不起作用):
foo=1
a='foo'
$a=42 # This does not work:"bash: foo=42: command not found"
# Want foo == 42 here
答案 0 :(得分:3)
您可以使用eval
。例如:
var1=abc
eval $var1="value1" # abc set to value1
答案 1 :(得分:2)
使用Select i.*, d.*, dd.min_deadline
from Items i cross join
Deadlines d join
(select dd.item_id, min(dd.deadline) as min_deadline
from Deadlines dd
group by dd.item_id
) dd
on dd.item_id = i.item_id;
指令:
select i.*,
(select min(d.deadline) from Deadlines d where d.item_id = i.item_id) as min_deadline
from items i;
检查declare
的内容:
declare -- $a=42
答案 2 :(得分:1)
你想:
eval "$a=42"
例如:
$ a=foo
$ eval "$a=42"
$ echo $foo
42