./*/可移植吗? [英] Is ./*/ portable?

查看:54
本文介绍了./*/可移植吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常在for循环中使用 ./*/,例如

I often use ./*/ in a for loop like

for d in ./*/; do
  : # do something with dirs
done

匹配当前工作目录中的所有非隐藏目录,但是我不确定这是否是一种可移植的方法.我在系统上安装了bash,dash和ksh,并且可以全部使用,但是由于 POSIX错误报告,但无济于事,这里也没有提及.

to match all non-hidden directories in current working directory, but I'm not really sure if this is a portable way to do that. I have bash, dash and ksh installed on my system and it works with all, but since POSIX spec doesn't say anything about it (or it says implicitly, and I missed it) I think I can't rely on it. I also checked POSIX bug reports, but to no avail, there's no mention of it there as well.

它的行为实现或文件系统相关吗?我在这里想念什么吗?我怎么知道它是否便携?

Is its behaviour implementation or filesystem dependent? Am I missing something here? How do I know if it's portable or not?

推荐答案

简短答案:是

长答案:

POSIX标准(来自opengroup)指出,/仅与扩展文件名中的斜杠匹配.由于Unix/Linux不允许在文件名中使用/,因此我认为在Unix/Linux系统上这是一个安全的假设.

The POSIX standard (from opengroup) states that / will only match slashes in the expanded file name. Since Unix/Linux does not allow / in the file name, I believe that this is a safe assumption on Unix/Linux systems.

从下面的粗体文字看来,即使对于允许在文件名中使用/的系统,POSIX标准也要求/不与此类匹配.文件.

From the bolded text below, it seems that even for systems that will allow / in the file name, the POSIX standard require that / will not be matched to such file.

在Windows上,文件名中似乎不允许/,但是我不是Windows的专家.

On Windows, looks like / is not allowed in the file name, but I'm not an expert on Windows.

来自 Shell编程语言§用于文件名扩展的模式:

路径名中的斜杠字符应通过在模式中使用一个或多个斜杠来明确匹配;它既不能与星号或问号特殊字符匹配,也不能与方括号表达式匹配.模式中的斜线应在方括号表达式之前标识;因此,斜杠不能包含在用于文件名扩展的模式括号表达式中....

附加说明-澄清路径名:

路径名在4.13中定义,在

The pathname is defined in 4.13, with explicit reference to pathname with trailing slash in General Concepts § Pathname Resolution.

包含至少一个非斜杠的路径名.字符,并且以一个或多个结尾的<斜杠>结尾.除非尾随<斜杠>之前的最后一个路径名组件,否则字符不能成功解析.字符命名一个现有目录或将在解析路径名后立即为该目录创建的目录条目.当未命名现有目录的路径名包含至少一个非斜杠时,使用路径名解析的接口可以指定其他约束.字符,并包含一个或多个结尾的<字符.

A pathname that contains at least one non-<slash> character and that ends with one or more trailing <slash> characters shall not be resolved successfully unless the last pathname component before the trailing <slash> characters names an existing directory or a directory entry that is to be created for a directory immediately after the pathname is resolved. Interfaces using pathname resolution may specify additional constraints when a pathname that does not name an existing directory contains at least one non-<slash> character and contains one or more trailing <slash> characters.

这篇关于./*/可移植吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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