跳过导航链接 | |
退出打印视图 | |
手册页第 1 部分:用户命令 Oracle Solaris 11 Information Library (简体中文) |
- 在扩展属性名称空间中执行命令
/usr/bin/runat file [command]
runat 实用程序用于在文件的隐藏属性目录中执行 shell 命令。实际上,此实用程序将当前工作目录更改为与文件参数关联的隐藏属性目录,然后在 bourne shell (/bin/sh) 中执行指定的命令。如果未提供 command 参数,则会派生一个交互式 shell。环境变量 $SHELL 定义了要派生的 shell。如果未定义该变量,则将使用缺省 shell (/bin/sh)。
file 参数可以是能够支持扩展属性的任何文件(包括目录)。在调用 runat 命令之前,不需要此文件具有任何属性,也不需要以任何方式准备此文件。
支持下列操作数:
可以支持扩展属性的任何文件(包括目录)。
要在属性目录中执行的命令。
如果 runat 无法访问 file 参数,或者 file 参数不支持扩展属性,将返回一个非零值退出状态。
有关扩展文件属性的详细说明,请参见 fsattr(5)。
runat 命令创建的进程上下文将其当前工作目录设置为包含文件扩展属性的隐藏目录。该目录的父代(“..”项)始终是指在命令行上提供的文件。因此,它可能不是目录。因此,依赖于格式正确的父代(即目录)的命令(如 pwd)可能会失败。
缺少 command 参数时,runat 将派生一个新的交互式 shell,其当前工作目录设置为给定文件的隐藏属性目录。请注意,如上所述,当目录的父代不是目录时,某些 shell(如 zsh 和 tcsh)将不能正常运行。这些 shell 不应该与 runat 一起使用。
示例 1 使用 runat 列出文件上的扩展属性
example% runat file.1 ls -l example% runat file.1 ls
示例 2 创建扩展属性
example% runat file.2 cp /tmp/attrdata attr.1 example% runat file.2 cat /tmp/attrdata > attr.1
示例 3 将属性从一个文件复制到另一个文件
example% runat file.2 cat attr.1 | runat file.1 "cat > attr.1"
示例 4 使用 runat 派生交互式 shell
example% runat file.3 /bin/sh
这将在 file.3 的属性目录中派生一个新的 shell。请注意,该 shell 无法确定您的当前目录是什么。要离开该属性目录,请退出派生的 shell,或者使用绝对路径更改目录 (cd)。
用于执行基本属性操作的推荐方法:
runat file ls [options]
runat file cat attribute
runat file cp absolute-file-path attribute
runat file rm attribute
runat file chmod mode attribute runat file chgrp group attribute runat file chown owner attribute
以上列表包括了已知的可与 runat 配合使用的命令。虽然许多其他命令也可使用,但是不能保证此列表范围外的任何命令都能够使用。任何要求能够确定当前工作目录的命令都可能会失败。此类命令的示例如下所示:
示例 5 在属性目录中使用 man
example% runat file.1 man runat >getcwd: Not a directory
示例 6 在属性目录中派生 tcsh shell
example% runat file.3 /usr/bin/tcsh tcsh: Not a directory tcsh: Trying to start from "/home/user"
已派生了一个新的 tcsh shell,其当前工作目录设置为用户的起始目录。
示例 7 在属性目录中派生 zsh shell
example% runat file.3 /usr/bin/zsh example%
虽然命令看上去已运行,但是 zsh 实际上仅仅是将当前工作目录更改为了 “/”。这可以通过使用 /bin/pwd 来查看:
example% /bin/pwd /
指定 runat 要调用的命令 shell。
将返回以下退出值:
file 参数引用的文件的属性目录不可访问。
无法执行所提供的 command 参数。
其他情况下,返回的退出状态是被调用来执行给定命令的 shell 的退出状态。
有关下列属性的描述,请参见 attributes(5):
|
open(2)、attributes(5)、fsattr(5)
对于无法确定当前工作目录时,命令在 runat 中为什么会失败,原因并不总是很明显的。错误结果可能是令人困惑的或是含糊的(请参见上述的 tcsh 和 zsh 示例)。