bash - 在 bash 脚本中将 x 放在变量之间(即 $foox$bar)

标签 bash

我在 bash 脚本中打印类似 10x10 的内容时遇到问题。这是我所拥有的:

#!/bin/bash

i="2"
array=(1024 2048 4096 6144)

while [ $i -lt 17 ]
do
    for j in "${array[@]}"
    do
    :
    secondpart=$((j / i))
    echo "$jx$jx$j and $secondpartx$secondpart"
done
    echo "\n"
    i=$[$i*2]
done

预期输出是: 1024x1024x1024 和 512x512

最佳答案

使用${j}x;否则它会查找名为 $jx

的变量

关于bash - 在 bash 脚本中将 x 放在变量之间(即 $foox$bar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35808473/

相关文章:

bash - 我可以在不修改现有所有者/组的情况下在 Bash 中为特定组/用户添加权限吗?

linux - bash - 命令行中的for循环

linux - bash 脚本看不到文件

python - 计算表中存在或不存在某个因素的组合

linux - 无法终止由 bash 脚本中的另一个 ssh session 启动的进程

linux - 在不知道文件名的情况下合并排序的文件

bash - 在 Bash 中使用管道命令获取特定输出

linux - 自动硬链接(hard link)文件,但只有一次

linux bash : line 18: syntax error near unexpected token `fi' Q2. sh:第 18 行: `fi'

python - 在 Windows 命令行上工作但在 Git Bash 终端上不工作的命令