在Bash中用空格循环遍历目录 [英] Loop over directories with whitespace in Bash

查看:62
本文介绍了在Bash中用空格循环遍历目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash脚本中,我想遍历当前工作目录中的所有目录并对它们进行处理.它们可能包含特殊符号,尤其是空格.我怎样才能做到这一点?我有:

In a bash script, I want to iterate over all the directories in the present working directory and do stuff to them. They may contain special symbols, especially whitespace. How can I do that? I have:

for dir in $( ls -l ./)
do
    if [ -d ./"$dir" ]

但是这会跳过名称中带有空格的目录.感谢您的帮助.

but this skips my directories with whitespace in their name. Any help is appreciated.

推荐答案

尝试一下:

for dir in */

这篇关于在Bash中用空格循环遍历目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆