作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通常在 bash 脚本中编写 for 循环时,我会这样写:
FILE[1]=/tempA/aaa
FILE[2]=tempB/bbb
for FILES in `ls -1 ${FILE[@]}`
do
echo $FILES
done
SOURCE[1]=/tempA/source/aaa
SOURCE[2]=/tempB/source/bbb
DEST[1]=/tempA/dest/
DEST[2]=/tempB/dest/
最佳答案
您可以使用 for
循环遍历数组:
$ SOURCE=( /tempA/source/aaa /tempB/source/bbb ) # declare SOURCE array
$ DEST=( /tempA/dest /tempB/dest ) # declare DEST array
$ for i in ${!SOURCE[@]}; do echo "${SOURCE[$i]}" "${DEST[$i]}"; done
/tempA/source/aaa /tempA/dest
/tempB/source/bbb /tempB/dest
echo
使用适当的命令。 (您可以以上述形式声明数组,从而无需逐一声明数组元素。)
关于bash - 如何在bash脚本中创建for循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20063078/
我是一名优秀的程序员,十分优秀!