手册页部分 1: 用户命令

退出打印视图

更新时间: 2014 年 7 月
 
 

runat(1)

名称

runat - 在扩展属性名称空间中执行命令

用法概要

/usr/bin/runat file [command]

描述

runat 实用程序用于在文件的隐藏属性目录中执行 shell 命令。实际上,此实用程序将当前工作目录更改为与文件参数关联的隐藏属性目录,然后在 bourne shell (/bin/sh) 中执行指定的命令。如果未提供 command 参数,则会派生一个交互式 shell。环境变量 $SHELL 定义了要派生的 shell。如果未定义该变量,则将使用缺省 shell (/bin/sh)。

file 参数可以是能够支持扩展属性的任何文件(包括目录)。在调用 runat 命令之前,不需要此文件具有任何属性,也不需要以任何方式准备此文件。

操作数

支持下列操作数:

file

可以支持扩展属性的任何文件(包括目录)。

command

要在属性目录中执行的命令。

错误

如果 runat 无法访问 file 参数,或者 file 参数不支持扩展属性,将返回一个非零值退出状态。

用法

有关扩展文件属性的详细说明,请参见 fsattr(5)

runat 命令创建的进程上下文将其当前工作目录设置为包含文件扩展属性的隐藏目录。该目录的父代(“..”项)始终是指在命令行上提供的文件。因此,它可能不是目录。因此,依赖于格式正确的父代(即目录)的命令(如 pwd)可能会失败。

缺少 command 参数时,runat 将派生一个新的交互式 shell,其当前工作目录设置为给定文件的隐藏属性目录。请注意,如上所述,当目录的父代不是目录时,某些 shell(如 zshtcsh)将不能正常运行。这些 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)。

用于执行基本属性操作的推荐方法:

display(显示)

runat file ls [options]

read

runat file cat attribute

create/modify(创建/修改)

runat file cp absolute-file-path attribute

delete

runat file rm attribute

permission changes(权限更改)
runat file chmod mode attribute
runat file chgrp group attribute
runat file chown owner attribute
interactive shell(交互式 shell)
runat file /bin/sh 或将您的 $SHELL 设置为 /bin/sh 并运行 runat file

以上列表包括了已知的可与 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
/

环境变量

SHELL

指定 runat 要调用的命令 shell。

退出状态

将返回以下退出值:

125

file 参数引用的文件的属性目录不可访问。

126

无法执行所提供的 command 参数。

其他情况下,返回的退出状态是被调用来执行给定命令的 shell 的退出状态。

属性

有关下列属性的说明,请参见 attributes(5)

属性类型
属性值
可用性
system/core-os
CSI
Enabled(已启用)
接口稳定性
Committed(已确定)

另请参见

open(2)attributes(5)fsattr(5)

附注

对于无法确定当前工作目录时,命令在 runat 中为什么会失败,原因并不总是很明显的。错误结果可能是令人困惑的或是含糊的(请参见上述的 tcshzsh 示例)。