Add this feature to the function you wrote for exercise 14.
The Linux basename utility has an optional second argument. If you give
the command basename path suffix, basename removes the suffix and the
prefix from path:
$ basename src/shellfiles/prog.bash .bash
prog
$ basename src/shellfiles/prog.bash .c
prog.bash
$ function bn2 () {
> if [ $# = 0 ]; then
> exit 1
> elif [ "$1" = "/" ]; then
> echo /
> else
> ans=$(echo $1 | sed 's:.*/::')
> if [ $# = 2 ]; then
> echo $ans | sed "s:\(.*\)$2$:\1:"
> else echo $ans
> fi
> fi
> }
You might also like to view...
What is the difference between the conditional AND and OR operators and their logical counterparts? How can incorrect use of the logical operators lead to unintended consequences in your program?
What will be an ideal response?
Which runlevel is typically not used?
A. zero B. one C. four D. five