Back References

Some versions of ksh allow for back references. Back references allow a sub-pattern to be referred to by number. The number refers to the instance of the open parentheses (counting from the left) starting with 1. Within a pattern, back references are referred to by a backslash followed by the number just mentioned. Therefore, the following example will match any string that begins and ends with the same letter, such as “mom”, “dad”, or “dumb-founded”:


Here is the breakdown of the expression. The @ means to match exactly one pattern; the (?) says to match exactly one character. The * says to match zero or more characters, and the \1 says to go back and reference what was after the first parenthesis. Therefore, it matches ...

Get Korn Shell Programming by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.