Module 35 dirname (SV)

Previous Table of Contents Next


Module 35
dirname (SV)

DESCRIPTION

The external dirname command parses the given path and returns only the pathname. Its cousin command basename returns the filename. Any suffix after the last / (slash) is deleted from the path, including the /. For instance, the command

 cj> dirname /u1/ts/mylogin/junk.c 

returns

 /u1/ts/mylogin 

The entire path (/ul/tech/mylogin) is returned but the filename junk.c is removed, along with the / separating the parent path and the filename.

COMMAND FORMAT

The format of the dirname command follows .

 dirname path 

Arguments

Only one argument may be passed to the dirname command.

path The path that is parsed and only the pathname is returned. The filename is removed.

RELATED COMMANDS

Refer to the basename command described in Module 18.

RELATED FILES

The dirname command writes to the standard output.

APPLICATIONS

The dirname command is normally used as a substitution command within a shell script. It can be used to reduce a full path parameter or variable down to a path without the filename.

TYPICAL OPERATION

In this activity you use the dirname command to find the directory of a command. Begin at the shell prompt.

1.    Type DIR= ˜dirname /usr/local/bin/newcmd ˜ and press Return . The DIR variable will be assigned the value of /usr/local/bin. The newcmd file is truncated from the pathname.
2.    Type echo $DIR and press Return . Notice that the path /usr/local/bin is displayed.
3.     Turn to Module 91 to continue the learning sequence.


Previous Table of Contents Next

Copyright Wordware Publishing, Inc.


Illustrated UNIX System V
Illustrated Unix System V/Bsd
ISBN: 1556221878
EAN: 2147483647
Year: N/A
Pages: 144
Authors: Robert Felps

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net