Skip to content

Files

Latest commit

 

History

History
27 lines (16 loc) · 690 Bytes

SC2020.md

File metadata and controls

27 lines (16 loc) · 690 Bytes

Pattern: Use of tr with duplicate characters

Issue: -

Description

tr is for transliteration, turning some characters into other characters. It doesn't match strings or words, only individual characters.

The solution is to use a tool that does string search and replace, such as sed.

Example of incorrect code:

echo 'hello world' | tr 'hello' 'goodbye'

In this case, it transliterates h->g, e->o, l->d, o->y, resulting in the string "goddb wbrdd" instead of "goodbye world".

Example of correct code:

echo 'hello world' | sed -e 's/hello/goodbye/g'

Further Reading