我在Ubuntu上使用bash,我在一个文件夹中有一些文件,有些文件名称中有空格,其他非文件.
我想要一个带文件名的数组.示例:[foo.txt,我是file.txt,bar.jpg等]
我的代码:
for x in "$(ls -1 test/)"; do fileList+=($x) done
我得到:[foo.txt,我,上午,a,file.txt,bar.jpg等]
如果我把fileList+=("$x")
我得到一个行数组[foo.txt我是file.txt bar.jpg等].
我该怎么做才能得到我想要的东西?
谢谢.
为什么不使用shell globs?例如
for x in test/*; do ...
要么
filelist=( test/* )
编辑:
shopt -s nullglob shopt -s dotglob
可能也想要.