'\" te .\" Copyright 1989 AT&T Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" 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 basename 1 "1997 年 3 月 18 日" "SunOS 5.11" "用户命令" .SH 名称 basename, dirname \- 提供路径名的各个部分 .SH 用法概要 .LP .nf \fB/usr/bin/basename\fR \fIstring\fR [\fIsuffix\fR] .fi .LP .nf \fB/usr/xpg4/bin/basename\fR \fIstring\fR [\fIsuffix\fR] .fi .LP .nf \fBdirname\fR \fIstring\fR .fi .SH 描述 .sp .LP \fBbasename\fR 实用程序删除 \fIstring\fR 中任何以 \fB/\fR 结尾的前缀和 \fIsuffix\fR(如果 \fIstring\fR 中存在),并将结果列显到标准输出。它通常在 shell 过程的替换标记 (\fB` `\fR) 中使用。 .SS "/usr/bin" .sp .LP \fIsuffix\fR 这种模式在 \fBexpr\fR(1) 手册页中给出了定义。 .SS "/usr/xpg4/bin" .sp .LP \fIsuffix\fR 字符串对于其包含的任何字符没有特殊的意义。 .sp .LP \fBdirname\fR 实用程序提供 \fIstring\fR 中最后一级以外的全部路径名。 .SH 示例 .LP \fB示例 1 \fR设置环境变量 .sp .LP 下面使用参数 \fB/home/sms/personal/mail\fR 调用的示例将环境变量 \fBNAME\fR 设置为名为 \fBmail\fR 的文件并将环境变量 \fBMYMAILPATH\fR 设置为字符串 \fB/home/sms/personal\fR: .sp .in +2 .nf example% \fBNAME=`basename \|$HOME/personal/mail`\fR example% \fBMYMAILPATH=`dirname \|$HOME/personal/mail`\fR .fi .in -2 .sp .LP \fB示例 2 \fR编译文件并移动输出 .sp .LP 此使用参数 \fB/usr/src/bin/cat.c\fR 调用的 shell 过程编译指定的文件并将输出移到当前目录的 \fBcat\fR 中: .sp .in +2 .nf example% \fBcc $1\fR example% \fBmv a.out `basename $1 .c`\fR .fi .in -2 .sp .SH 环境变量 .sp .LP 有关影响 \fBbasename\fR 和 \fBdirname\fR 执行的以下环境变量的说明,请参见 \fBenviron\fR(5):\fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR。 .SH 退出状态 .sp .LP 将返回以下退出值: .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 出现错误。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .SS "/usr/bin" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os .TE .SS "/usr/xpg4/bin" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/xopen/xcu4 _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBexpr\fR(1)、\fBbasename\fR(3C)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBstandards\fR(5)