Implement dirname as a bash function. Make sure it behaves sensibly when given such arguments as /.

The dirname utility treats its argument as a pathname and writes to standard out-
put the path prefix—that is, everything up to but not including the last component:
$ dirname a/b/c/d
a/b/c
If you give dirname a simple filename (no / characters) as an argument,
dirname writes a . to standard output:
$ dirname simple


$ function dn () {
> if [ $# = 0 ]
> then
> exit 1
> elif [ "$1" = "/" ]
> then
> echo /
> elif (echo "$1" | grep -v "/" > /dev/null 2>&1)
> then
> echo .
> else
> echo $1 | sed 's:\(.*\)/.*:\1:'
> fi
> }

Computer Science & Information Technology

You might also like to view...

There are many cases in which the object being copied is about to be destroyed, such as a temporary object that was returned from a function by value or a local object that’s going out of scope. In such cases, it’s better to move the contents of the object that’s about to be destroyed into the destination object, thus avoiding ________.

a. a memory leak b. a runtime error c. a memory exhaustion error d. any copying overhead

Computer Science & Information Technology

Used appropriately, color can create interest by emphasizing material and promoting understanding.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

A printer is an example of a(n) ________

A) integral part of every computer B) output device C) processing device D) system device

Computer Science & Information Technology

Prompt() is a JavaScript ________ associated with the window object

Fill in the blank(s) with correct word

Computer Science & Information Technology