小编sup*_*ted的帖子

带空格的 Bash 变量(目录)

我试图在/foo保留列出目录中的空格的同时回显所有文件。目前,名为目录"bar1 bar2"将回声出作为/path/to/foo/bar1/然后/bar2file.txt全部上新的生产线。我需要它来 echo/path/to/foo/bar1 bar2/file.txt/path/to/foo/bar1\ bar2/file.txt.

for file in $(find /path/to/foo/ -type f); do
  if [[ ... ]]; then
    echo "${file}"
  fi
done
Run Code Online (Sandbox Code Playgroud)

还试过:

for file in $(find /path/to/foo/ -type f | sed 's/ /\ /g'); do
  if [[ ... ]]; then
    echo "${file}"
    echo "$file" # variations i've tried
    echo $file   # variations i've tried
    echo ${file}
    otherCommand "${file}"
  fi
done
Run Code Online (Sandbox Code Playgroud)

linux bash shell ubuntu bash-scripting

6
推荐指数
1
解决办法
2167
查看次数

查找文件但排除几个目录?

如何find列出每个文件但从搜索中排除少数目录?

find / -type f -not -path "./foo*" -not -path "/bar*" -print
Run Code Online (Sandbox Code Playgroud)

我在其他 stackexchanges 上看到过示例,例如./,但我尝试过的似乎都不起作用。

这有点有效:

find / -type f -not -path "*foo*" -not -path "*bar*" -print
Run Code Online (Sandbox Code Playgroud)

但事实并非如此;它还从搜索结果中排除名为“foo”和“bar”的文件。

linux bash shell ubuntu bash-scripting

5
推荐指数
1
解决办法
5854
查看次数

标签 统计

bash ×2

bash-scripting ×2

linux ×2

shell ×2

ubuntu ×2