Shell:嵌套for循环

发布于 2024-10-02 15:55:08 字数 199 浏览 0 评论 0原文

不知何故,在以下脚本中,$i的值
第 3 行没有展开。知道为什么吗?

for i in `cat test.txt`
do
        for j in `find . -name $i`
        do
                echo $j
        done
done

Somehow in the following script, value of $i
is not expanded on line 3. Any idea why?

for i in `cat test.txt`
do
        for j in `find . -name $i`
        do
                echo $j
        done
done

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝眸 2024-10-09 15:55:08

修复行结尾后:

xargs --arg-file test.text -I % find . -name "%"

不需要嵌套循环。

After you fix the line endings:

xargs --arg-file test.text -I % find . -name "%"

No need for nested loops.

万劫不复 2024-10-09 15:55:08
for i in `cat test.txt | sed -e "s/\r//g"`; do find -name $i; done

大问题:cygwin 支持 sed?

或 cygwin

d2u test.txt; for i in `cat test.txt`; do find -name $i; done

或 linux

dos2unix test.txt; for i in `cat test.txt`; do find -name $i; done
for i in `cat test.txt | sed -e "s/\r//g"`; do find -name $i; done

big question: cygwin support sed?

or cygwin

d2u test.txt; for i in `cat test.txt`; do find -name $i; done

or linux

dos2unix test.txt; for i in `cat test.txt`; do find -name $i; done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文