Suppose I have a file named doc with content:
{}
[]
Now I want to translate all the ‘{‘ and ‘[‘ into ‘(‘ and ‘}’ and ‘]’ into ‘)’. So far, I can translate ‘{}’ and ‘[‘ correctly, but I can’t translate ‘]’, using this shell command:
cat doc | tr [\[] [\(] | tr [\{] [\(] | tr [\}] [\)] | tr [\]] [\)] | cat
The output is:
()
(]
So far, it can translate other character, except for ‘]’. Do you know why?
This is a shell exercise, which asks to translate all ‘{}’ and ‘[]’ in a .c file into ‘()’. I just want to simply it here.
Here’s one example that works fine:
Here’s another example: