Reputation: 3
From another cross-platform program I would like to use the UnxUtils tr.exe program exactly as under Unix but I can't manage to get it to work, the issue being the escaping. Here's an example.
Create a file blah.txt with content
%^&<>|'`,;=()!\"\\[].*?
Then
type blah.txt | tr.exe "*" "X"
tr.exe: extra operand `blah.txt' Try `tr.exe --help' for more information.
The problem is that Windows expands * to the files in the directory. But under Unix this is no problem. No matter what I tried, I can't escape the * properly under Windows. Similarly with the quotation mark ". Even if I can figure out how to rewrite the escaping properly, it will be a mess to apply this correction to a set of characters.
I managed to get sed.exe from the UnxTools to work consistently because here I can use program files with the -f option so that I don't need to escape things.
Any ideas?
Upvotes: 0
Views: 1083
Reputation: 70943
Some easy portable ways to deal with the file globbing when using *
(by the way, as MSalters points it is not a windows feature)
type blah.txt | tr.exe \52 X
type blah.txt | tr.exe [=*=] X
Upvotes: 0
Reputation: 179991
The problem is that Windows (CMD.EXE) does not expand *
. Ever. That's why escaping won't fix it. That's how dir /s *.txt
can find text files in subdirectories. It wouldn't work if *.txt
was expanded in the directory where you currently are.
That's why Windows tools need to handle *
. Apparently tr.exe
gets it wrong.
Upvotes: 1