In Linux and other OS, file can contain characters like (,),[,],<space>,
etc. in their names.
Whenever I try to use any of these files in my bash command like cat, ls, etc. I am required to escape them like below :
filename abc(10-oct).txt
cat abc(10-oct).txt wont work.
If I precede "("
and ")"
characters with "\"
character like
cat abc\(10-oct\).txt
This works
I am trying to automate some of Linux shell commands via Java program.And I am not sure of what all characters I must take care of and escape them.
If someone may point to a resource where I can get an entire list of characters, it would be a great help.
Many Thanks
Quoting from Shell Command Language:
The following characters must be quoted if they are to represent themselves:
| & ; < > ( ) $ ` \ " ' <space> <tab> <newline>
and the following may need to be quoted under certain circumstances. That is, these characters may be special depending on conditions described elsewhere in this specification:
* ? [ # ~ = %
The various quoting mechanisms are the escape character, single-quotes and double-quotes.
It also says:
Enclosing characters in single-quotes (' ') preserves the literal value of each character within the single-quotes. A single-quote cannot occur within single-quotes.
And:
Enclosing characters in double-quotes (" ") preserves the literal value of all characters within the double-quotes, with the exception of the characters dollar-sign, backquote and backslash...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With