![](/img/trans.png)
[英]How to grep contents from list of files from Linux ls or find command
[英]Store filenames from linux “ls” command into separate array/list elements
如何将文件名及其关联的扩展名“仅”存储到“ bash”脚本中的数组或列表中? 以某种方式将每个文件名存储在单独的元素中,而不会产生其他文件信息,例如创建日期或权限级别……
我喜欢做:
filelist=`ls -1 /somedir/`
然后遍历$ filelist。
ls -1
仅显示文件名,不包含任何其他属性。
像这样:
root@myserver-1-00:~# filelist=($(ls))
root@myserver-1-00:~# echo $filelist
Desktop
root@myserver-1-00:~# echo ${filelist[0]}
Desktop
root@myserver-1-00:~# echo ${filelist[1]}
Documents
root@myserver-1-00:~# echo ${filelist[2]}
Downloads
variable = {$(yourcommand))->使输出被分配为数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.