I need to specify a password with the character #
, but it comments the line.
How do I force it to be be read literally?
Ex : I need to put PASSWORD=xpto#123
. Without commenting the 123
If that
PASSWORD=xpto#123
was code in any Bourne-like shell (bash, dash, ksh, zsh...), that #
would not be taken as a comment. In those shells, #
only introduces a comment when at the start of a shell token (so at the start of the line or following blanks or ;
, |
, &&
...).
It would be taken as a comment character in the rc
shell or derivatives¹ (which are other shells that have assignment in the var=value
shape), but I doubt you're using those.
Most likely, you're trying to use that in some configuration file, where it's also common for #
to introduce comments.
There is no real standard for configuration files, so how to escape that character if it's otherwise treated as a comment will depend on the actual configuration file.
Best is to read the manual for that configuration file or the software it is for.
Common ways to escape characters include double quotes ("..."
), single quotes ('...'
) or backslash preceding the character. It may also be possible to enter the character using octal sequences² (\043
) or hex² (\x23
) or Unicode (\u0023
)... There may also be some variations as to how the quotes are handled (whether backslash or other characters are special within the quotes...).
¹ In the rc
shell , the only quoting operator is '...'
(and a single quote itself is represented with ''
within those singe quotes). In the es
shell (derived from Byron Rakitzis's clone of rc
for Unix), you can also use \#
, \043
or \x23
.
² Note that those represent the byte value, so a \x43
would only encode a #
in the ASCII character set or compatible, which should be the immense majority or charsets in use nowadays, the only exceptions would be some rare IBM systems that still use EBCDIC. But that's something you would want to keep in mind when using non-ASCII characters. \u0023
on the other hand is guaranteed (by Unicode) to be the #
character.
#
would not be taken as a comment here (as it's right after theo
) in any Bourne-like shell. – Stéphane Chazelas Sep 07 '19 at 07:14PASSWORD=xpto#123
? In a configuration file? In what configuration file? For what software? – Stéphane Chazelas Sep 07 '19 at 07:15