Write a function called rightmatch that takes two arguments as shown:
rightmatch value pattern
where value is a sequence of one or more characters, and pattern is a shell pattern that is to be removed from the right side of value. The shortest matching pattern should be removed from value and the result written to standard output. Here is some sample output:
$ rightmatch test.c .c
test
$ rightmatch /usr/spool/uucppublic '/*'
/usr/spool
$ rightmatch /usr/spool/uucppublic o
/usr/spool/uucppublic
$
The last example shows that the rightmatch function should simply echo its first argument if it does not end with the specified patter
# rightmatch value pattern
# remove shortest matching pattern from value
# accomplished with ${var%patt}
value=$1
pattern=$2
echo ${value%$pattern}
You might also like to view...
Describe the Preview view mode and its keyboard shortcut.
What will be an ideal response?
C# views each file as a ________.
a) sequential stream of bytes b) sequential stream of bits c) sequential stream of characters d) sequential stream of strings e) None of the above.