shell - 如何将文本与扩展变量组合成 Fish 中的变量扩展

标签 shell fish

我需要通过 $bootlog5 回显 $bootlog1 的值。

类似这样的事情:

for n in (seq 5)
    set bootlog$n value
    echo $bootlog$n
end

但我似乎无法弄清楚。

最佳答案

更容易使用中间变量:

for n in (seq 5)
    set var bootlog$n
    set $var (random)
    echo $var = $$var
end
bootlog1 = 20819
bootlog2 = 19479
bootlog3 = 11254
bootlog4 = 23223
bootlog5 = 23674

关于shell - 如何将文本与扩展变量组合成 Fish 中的变量扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65132069/

相关文章:

c++ - 从 C++ 设置系统变量

iphone - 在 MacOS 上通过命令行连接到蓝牙设备 (iPhone)

bash - Bash 中的临时输入重定向

linux - Bash(或其他 shell ): wrap all commands with function/script

linux - FISH:如何在启动 Fish 时设置特定的 $fish_function_path?

shell - 在 fish shell 中压缩 for 循环(循环多个列表)

shell - awk:比较两个包含数字的文件

linux - 如何在 Ubuntu 中为 shell 脚本创建可执行文件?

TIDE 内的 Fish shell git 提示符

linux - fish、zsh、bash 可以导入同一个配置文件吗?