If I call a variable as a list of files:
如果我调用一个变量作为文件列表:
files=$(ls *.txt)
* . txt文件= $(ls)
I then want to remove the first item (file) in the list
然后,我要删除列表中的第一个项(文件)
Thanks
谢谢
Clive
克莱夫。
1 个解决方案
#1
2
You should never parse the output of ls
; see http://mywiki.wooledge.org/ParsingLs.
永远不要解析ls的输出;见http://mywiki.wooledge.org/ParsingLs。
Fortunately, in your case you're not actually using any of ls
's functionality; Bash already handles the *.txt
part, so the ls
is pretty redundant.
幸运的是,在您的例子中,您实际上并没有使用任何ls的功能;Bash已经处理*。txt部分,所以ls是多余的。
You can write this:
你可以这样写:
# Set files to an array of the files with names ending in '*.txt':
files=(*.txt)
# Set files to an array consisting of ${files[1]}, ${files[2]}, ...:
files=("${files[@]:1}")
(See the Bash Reference Manual, § 3.5.3 "Shell Parameter Expansion"; search for ${parameter:offset}
.)
(参见Bash参考手册,§3.5.3“壳参数扩展”;搜索$ {参数:抵消})。
#1
2
You should never parse the output of ls
; see http://mywiki.wooledge.org/ParsingLs.
永远不要解析ls的输出;见http://mywiki.wooledge.org/ParsingLs。
Fortunately, in your case you're not actually using any of ls
's functionality; Bash already handles the *.txt
part, so the ls
is pretty redundant.
幸运的是,在您的例子中,您实际上并没有使用任何ls的功能;Bash已经处理*。txt部分,所以ls是多余的。
You can write this:
你可以这样写:
# Set files to an array of the files with names ending in '*.txt':
files=(*.txt)
# Set files to an array consisting of ${files[1]}, ${files[2]}, ...:
files=("${files[@]:1}")
(See the Bash Reference Manual, § 3.5.3 "Shell Parameter Expansion"; search for ${parameter:offset}
.)
(参见Bash参考手册,§3.5.3“壳参数扩展”;搜索$ {参数:抵消})。