【发布时间】:2021-02-05 01:52:51
【问题描述】:
有一个文件,每一行显示不同的文件路径。
```
my_file
/the/first/path/file1
/the/second/path/file2
....
```
我想使用 for 循环在每个文件中查找一个字符串。
```
for i in $(cat my_file); do cd "$i"; done | grep -w string "$i"
```
但这似乎对我不起作用。我正在为所有文件目录获取这个
-bash: cd: /the/first/path/file1: No such file or directory
我做错了什么?在此先感谢您的帮助
【问题讨论】:
标签: linux bash for-loop grep cd