猛击;将目录更改为以 2* 或 21* 开头的文件夹
我有一系列文件夹,它们是根据创建日期和其他一些信息命名的;即
220310_AS
220307_DF
220228_1A
..
211228_QR
..
201224_HH
如何在 bash 脚本中循环遍历以 22 或 21 开头的文件夹? 这是我的代码的一部分,不起作用
..
for dd in */2*; do
cd "$dd"
#do something
eval "ls"
cd ..
..
I have a series of folders which are named based on the date of creation and some other information; i.e.
220310_AS
220307_DF
220228_1A
..
211228_QR
..
201224_HH
How can I in a bash script loop over folders which start with 22 or 21?
Here is part of my code which does not work
..
for dd in */2*; do
cd "$dd"
#do something
eval "ls"
cd ..
..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的通配符
*/2*
匹配原始目录下 2 级的目录。因此,要返回原始目录,您需要cd ../..
而不是cd ..
。您还可以在子 shell 中执行
cd
,然后只需退出 shell 即可返回到原始目录。Your wildcard
*/2*
matches directories 2 levels below the original directory. So to get back to the original directory, you needcd ../..
instead ofcd ..
.You could also do the
cd
in a subshell, then simply exiting the shell will return you to the original directory.