【问题标题】:just started learning shell script, can't solve this problem刚开始学习shell脚本,解决不了这个问题
【发布时间】:2022-09-22 21:51:33
【问题描述】:
foo=username
bar=foo

a=$(eval echo \\$$bar)
echo ${!bar}
echo $(eval echo \\$${a^^}) # expected val

如果我不想通过变量赋值得到结果,我该怎么办?

我知道它需要一个变量名而不是一个字符串

echo $(eval echo \\$${${!bar}^^}) # error bad substitution
  • 你想做什么?

标签: linux bash shell


【解决方案1】:

我相信这是你想要开始的:

foo=username
bar=$foo

... 其中username 是文字字符串,您要放入名为foo 的变量中,而$foo 是您要放入变量@ 的变量foo 的值987654326@。

【讨论】:

  • 如果我想通过第二段代码获得结果,我该怎么办
猜你喜欢
  • 1970-01-01
  • 2011-05-12
  • 2023-01-20
  • 2014-01-03
  • 2018-06-16
  • 1970-01-01
  • 2020-10-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多