linux – Bash for循环数组,文件来自(*)只显示第一个元素
发布时间:2020-12-15 08:38:45 所属栏目:Linux 来源:互联网
导读:我想将当前目录的文件放在一个数组中,并用这个脚本回显每个文件: #!/bin/bashfiles=(*)for file in $filesdo echo $filedone# This demonstrates that the array in fact has the values from (*)echo ${files[0]} ${files[1]} ec
我想将当前目录的文件放在一个数组中,并用这个脚本回显每个文件: #!/bin/bash files=(*) for file in $files do echo $file done # This demonstrates that the array in fact has the values from (*) echo ${files[0]} ${files[1]} echo done 输出: echo.sh echo.sh read_output.sh done 有谁知道为什么只有第一个元素在for循环中打印? 解决方法$files扩展到数组的第一个元素.尝试echo $files,它只会打印数组的第一个元素. 由于同样的原因,for循环只打印一个元素. 要扩展到数组的所有元素,您需要将其写为${files [@]}. 迭代Bash数组元素的正确方法: for file in "${files[@]}" (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 从Linux上载10,000,000个文件到Azure blob存储
- 在Linux上,如果点击,我可以获得不同的键吗?
- linux-kernel – 编译Linux内核错误xt_CONNMARK.h
- LINUX实操:RAID磁盘阵列的搭建(以raid0、raid1、raid5、r
- linux – 如何从“grep”中排除所有“权限被拒绝”的结果行
- 使用Linux上的Team Explorer Everywhere设置工作区
- linux – cgroups隔离(分离组进程)
- 我怎么知道我是在运行32位还是64位Linux?
- Sed / Awk – 删除ldif转储中的空白/连接行
- linux – xprop设置atom属性的多个字段