I know : echo "blah blah" >file.txt
works.
and that echo "" >file.txt
works too.
but, what if I want to echo only ONE "
(double quote) in a file.
echo ">file.txt
doesn't work, is it possible doing it in a one line command?
I know : echo "blah blah" >file.txt
works.
and that echo "" >file.txt
works too.
but, what if I want to echo only ONE "
(double quote) in a file.
echo ">file.txt
doesn't work, is it possible doing it in a one line command?
The escape character for the Windows shell is
^
, so:The quote does not need to be escaped to echo it, but characters appearing after the 1st quote will be considered quoted, even if there is no closing quote, so the trailing redirection will not work unless the quote is escaped.
It is simple to redirect the echo of a single quote to a file without escaping - simply move the redirection to the front.
The complete answer is a bit complex because the quote system is a state machine. If currently "off", then the next quote turns it "on" unless the quote is escaped as
^"
. Once the quote machine is "on", then the next quote will always turn it off - the off quote cannot be escaped.Here is a little demonstration
And here are the results
Addendum
While it is not possible to escape a closing quote, it is possible to use delayed expansion to either hide the closing quote, or else counteract it with a phantom re-opening quote.
results