'\" te .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Portions Copyright (c) 2007, 2011, Oracle and/or its affiliates.All rights reserved. .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation.Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation.In the following statement, the phrase "this text" refers to portions of the system documentation.Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document.The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.This notice shall appear on any product containing this material. .TH command 1 "2011 年 7 月 12 日" "SunOS 5.11" "用户命令" .SH 名称 command \- 执行简单命令 .SH 用法概要 .SS "/usr/bin/command" .LP .nf \fBcommand\fR [\fB-p\fR] \fIcommand_name\fR [\fIargument\fR]... .fi .LP .nf \fBcommand\fR [\fB-v\fR | \fB-V\fR] \fIcommand_name\fR .fi .SS "ksh" .LP .nf \fBcommand\fR [\fB-pvxV\fR] [\fIcommand_name\fR [\fIargument\fR...]] .fi .SH 描述 .sp .LP \fBcommand\fR 实用程序可使 shell 将参数当作简单命令,禁止 shell 查找函数。 .sp .LP 如果 \fIcommand_name\fR 与某个特殊内置实用程序的名称相同,则将删除相应的特殊属性。在其他任何方面,如果 \fIcommand_name\fR 不是函数的名称,则 \fBcommand\fR(不带选项)的作用与省略 \fBcommand\fR 相同。 .sp .LP \fBcommand\fR 实用程序还可提供有关 shell 如何解释命令名称的信息。请参见 \fB-v\fR 和 \fB-V\fR。 .SS "ksh" .sp .LP 如果不使用 \fB-v\fR 或 \fB-V\fR 选项,\fBcommand\fR 将根据 \fIargument\fR 指定的参数执行 \fIcommand_name\fR,禁止通常执行的 shell 查找函数。此外,如果 \fIcommand\fR 是特殊内置命令,则将删除相应的特殊属性,以使失败不会导致执行命令的脚本终止。 .sp .LP 如果指定了 \fB-v\fR 或 \fB-V\fR 选项,\fBcommand\fR 等效于 \fBwhence\fR(1)。 .SH 选项 .sp .LP \fB/usr/bin/command\fR 支持以下选项: .sp .ne 2 .mk .na \fB\fB-p\fR\fR .ad .RS 6n .rt 使用 \fBPATH\fR 的缺省值执行搜索命令,保证可找到所有标准实用程序。 .RE .sp .ne 2 .mk .na \fB\fB-v\fR\fR .ad .RS 6n .rt 将一个字符串写入标准输出,指明 shell 在当前 shell 执行环境中调用 \fIcommand_name\fR 但不调用 \fIcommand_name\fR 所用的路径或命令。 .RS +4 .TP .ie t \(bu .el o 实用程序、常规内置实用程序、\fIcommand_names\fR(包括斜杠字符)和任何实现程序提供的使用 \fBPATH\fR 变量的函数将作为绝对路径名称写入。 .RE .RS +4 .TP .ie t \(bu .el o Shell 函数、特殊内置实用程序、不与 \fBPATH\fR 搜索关联的常规内置实用程序和 shell 保留字只作为其名称写入。 .RE .RS +4 .TP .ie t \(bu .el o 别名作为表示别名定义的命令行写入。 .RE .RS +4 .TP .ie t \(bu .el o 否则,不会写入任何输出,退出状态将反映未找到名称。 .RE .RE .sp .ne 2 .mk .na \fB\fB-V\fR\fR .ad .RS 6n .rt 将一个字符串写入标准输出,指明 shell 在当前 shell 执行环境中不调用 \fIcommand_name\fR 的情况下如何解释 \fIcommand_name\fR 操作数中指定的名称。尽管该字符串的格式未指定,但是它指明了 \fIcommand_name\fR 属于以下哪种类别,并且包含规定的信息: .RS +4 .TP .ie t \(bu .el o 实用程序、常规内置实用程序和任何实现程序提供的使用 \fBPATH\fR 变量的函数解释为其本身,在字符串中包含绝对路径名称。 .RE .RS +4 .TP .ie t \(bu .el o 其他 shell 函数解释为函数。 .RE .RS +4 .TP .ie t \(bu .el o 别名解释为别名,在字符串中包含其定义。 .RE .RS +4 .TP .ie t \(bu .el o 特殊内置实用程序解释为特殊内置实用程序。 .RE .RS +4 .TP .ie t \(bu .el o 不与 \fBPATH\fR 搜索关联的常规内置实用程序解释为常规内置实用程序。 .RE .RS +4 .TP .ie t \(bu .el o Shell 保留字解释为保留字。 .RE .RE .SS "ksh" .sp .LP \fBksh\fR \fBcommand\fR 支持以下选项: .sp .ne 2 .mk .na \fB\fB-p\fR\fR .ad .RS 6n .rt 搜索缺省路径而非 \fBPATH\fR 的值定义的路径。 .RE .sp .ne 2 .mk .na \fB\fB-v\fR\fR .ad .RS 6n .rt 等效于: .sp .in +2 .nf whence \fIcommand\fR [\fIargument\fR ...] .fi .in -2 .sp .RE .sp .ne 2 .mk .na \fB\fB-V\fR\fR .ad .RS 6n .rt 等效于: .sp .in +2 .nf whence -v \fIcommand\fR [\fIargument\fR ...] .fi .in -2 .sp .RE .sp .ne 2 .mk .na \fB\fB-x\fR\fR .ad .RS 6n .rt 如果因参数过多而命令失败,将多次调用命令,每次调用传递一部分参数。每次调用时,将会传递在扩展到多个参数的第一个词之前以及在扩展到多个参数的最后一个词之后出现的参数。退出状态为最大调用退出状态。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fIargument\fR\fR .ad .RS 16n .rt 当作 \fIcommand_name\fR 的参数的字符串之一。 .RE .sp .ne 2 .mk .na \fB\fIcommand_name\fR\fR .ad .RS 16n .rt 实用程序或特殊内置实用程序的名称。 .RE .SH 示例 .LP \fB示例 1 \fR创建一个始终输出新工作目录的 \fBcd\fR 版本 .sp .LP 以下示例将创建一个始终只输出新工作目录一次的 \fBcd\fR 版本: .sp .in +2 .nf cd() { command cd "$@" >/dev/null pwd } .fi .in -2 .sp .LP \fB示例 2 \fR启用使脚本避免受父项欺骗的\fB安全 shell 脚本\fR .sp .LP 以下示例将启用使脚本避免受父项欺骗的\fB安全 shell 脚本\fR: .sp .in +2 .nf IFS=' \&' # The preceding value should be . # Set IFS to its default value. \eunalias -a # Unset all possible aliases. # Note that unalias is escaped to prevent an alias # being used for unalias. unset -f command # Ensure command is not a user function. PATH="$(command -p getconf _CS_PATH):$PATH" # Put on a reliable PATH prefix. # ... .fi .in -2 .sp .sp .LP 在这种情况下,如果对 \fBPATH\fR 指定的目录具有适当的权限,则脚本可确保调用的任何实用程序都是打算调用的那个。这样做非常谨慎,因为假定可以存在实现扩展,就会在调用脚本时存在用户函数。该功能并未在本文档中指定,但是并不禁止将其作为扩展功能。例如,\fBENV\fR 变量在调用脚本之前调用用户启动脚本。此类脚本可以定义用来欺骗应用程序的函数。 .SH 环境变量 .sp .LP 有关影响 \fBcommand\fR 执行的以下环境变量的说明,请参见 \fBenviron\fR(5):\fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR。 .sp .ne 2 .mk .na \fB\fBPATH\fR\fR .ad .RS 8n .rt 确定命令搜索期间使用的搜索路径,\fB-p\fR 选项下所述的除外。 .RE .SH 退出状态 .SS "/usr/bin/command" .sp .LP 如果指定了 \fB-v\fR 或 \fB-V\fR 选项,将返回以下退出值: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 6n .rt 成功完成。 .RE .sp .ne 2 .mk .na \fB\fB>0\fR\fR .ad .RS 6n .rt 无法找到 \fIcommand_name\fR 或出现错误。 .RE .sp .LP 否则,将返回以下退出值: .sp .ne 2 .mk .na \fB\fB126\fR\fR .ad .RS 7n .rt \fIcommand_name\fR 指定的实用程序已找到但无法调用。 .RE .sp .ne 2 .mk .na \fB\fB127\fR\fR .ad .RS 7n .rt \fBcommand\fR 实用程序出现错误或无法找到 \fIcommand_name\fR 指定的实用程序。 .RE .sp .LP 否则,\fBcommand\fR 的退出状态将为 \fBcommand\fR 的参数指定的简单命令的退出状态。 .SS "ksh" .sp .LP 如果调用了 \fIcommand\fR,则 \fBcommand\fR 的退出状态将为 \fIcommand\fR 的退出状态。否则,将为以下状态之一: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 7n .rt \fIcommand_name\fR 已成功完成。 .RE .sp .ne 2 .mk .na \fB\fB>0\fR\fR .ad .RS 7n .rt \fB-v\fR 或 \fB-V\fR 已指定但出现错误。 .RE .sp .ne 2 .mk .na \fB\fB126\fR\fR .ad .RS 7n .rt \fIcommand_name\fR 已找到但无法调用。 .RE .sp .ne 2 .mk .na \fB\fB127\fR\fR .ad .RS 7n .rt 无法找到 \fIcommand_name\fR。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .SS "/usr/bin/command" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SS "ksh" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ 接口稳定性Uncommitted(未确定) .TE .SH 另请参见 .sp .LP \fBksh\fR(1)、\fBsh\fR(1)、\fBtype\fR(1)、\fBwhence\fR(1)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBstandards\fR(5)