跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • linux的文件/夹名有空格的情况下应该怎么遍历它?
未分類
27 7 月 2020

linux的文件/夹名有空格的情况下应该怎么遍历它?

嗷嗷 大佬有话说 :

linux的文件/夹名有空格的情况下应该怎么遍历它?

Linux的数组是用空格分隔的

获取文件夹名后保存到一个数组里

遍历它,就发现把一个文件名按空格分成几个了。应该怎么解决呢?

https://developer-forum-online.cdn.bcebos.com/a50cfd7a-17e0-4aa7-b6eb-183c5004d20c.png

志明 大佬有话说 :

不知道你写的啥脚本,这是我之前的笔记,用的print0
@localhost ~]# find -name "*.txt"
./1 2.txt
./a b.txt
# find -name "*.txt" -print0
./1 2.txt./a b.txt#find -name "*.txt" -print0|xargs ls -l
xargs: WARNING: a NUL character occurred in the input.It cannot be passed through in the argument list.Did you mean to use the –null option?
ls: cannot access ‘./1’: No such file or directory
ls: cannot access ‘2.txt’: No such file or directory
ls: cannot access ‘b.txt’: No such file or directory
# find -name "*.txt" -print0|xargs -0 ls -l
-rw-r–r–. 1 root root 0 Jul 26 20:23 ‘./1 2.txt’
-rw-r–r–. 1 root root 0 Jul 26 20:23 ‘./a b.txt’
#

Developer_HZH 大佬有话说 :

试试for i in ./[MICAT* ; do echo "${i}" ; done

manc 大佬有话说 :

加引号

嗷嗷 大佬有话说 :

Developer_HZH 大佬有话说 : 2020-7-27 16:41
试试for i in ./

恐怖如斯,听君一席话,胜读十年书

嗷嗷 大佬有话说 :

志明 大佬有话说 : 2020-7-27 16:34
不知道你写的啥脚本,这是我之前的笔记,用的print0
# find -name "*.txt"
./1 2.txt

print0,学到了

我来打酱油的 大佬有话说 :

加一个 IFS=$’n’

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具