1

I have a command

path/to/forticlientsslvpn_cli --server <host>:<port> --vpnuser testpass\101

When I run the script, linux puts a space between testpass and 101. I want the script to see "testpass\101" as the username

I hope I make sense

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

2 Answers2

10

This is happening because \ is an escape character.

Either use quoting

path/to/forticlientsslvpn_cli --server <host>:<port> --vpnuser 'testpass\101'

or use an escaped backslash:

path/to/forticlientsslvpn_cli --server <host>:<port> --vpnuser testpass\\101
Panki
  • 6,664
  • Awesome! Thanks, I used the escaped backlash option. – Tlou Rammala May 05 '20 at 11:05
  • 1
    You might want to use single quotes to protect backslashes, since they're still special for escaping some characters within double-quotes, e.g. the backslash itself. E.g. a double backslash would be either '\\' or "\\\\". – ilkkachu May 05 '20 at 11:25
  • Thanks for your addendum, I have edited the answer. @OP: Please mark the answer as "accepted" if it solved your question. – Panki May 05 '20 at 11:36
  • Hi, could you explain why would \ add an space? I'm having trouble understand it, I think it's the same as testpass'1'01, where does the space come from? – dedowsdi May 05 '20 at 12:09
  • 1
    @dedowsdi, there's no space. you're right testpass\101 is the same as testpass101. – ilkkachu May 05 '20 at 12:37
7

For completeness, with the bash shell and on ASCII based systems, with quoting alone:

  • 'testpass\101' (by far the best)
  • testpass\\101
  • "testpass\101" or "testpass\\101" (latter better)
  • $'testpass\\101'
  • $'testpass\u005c101' or $'testpass\U0000005c101' (U+005C being the Unicode code point for backslash)
  • $'testpass\x5c101' (where 0x5C is the byte value of the ASCII encoding of \)
  • $'testpass\134101' (same in octal)

For more details, see How to use a special character as a normal one?