linusg linusg - 6 months ago 19
Bash Question

Cross-platform, safe to use command line string separator

For a new feature in

PyInstaller
, we need a command line option receiving a string with any separator in it. Here's the discussion: https://github.com/pyinstaller/pyinstaller/pull/1990.

Example:

pyinstaller --add-data="file.txt?dir"


?
is the separator here, this should be another character. It's not guaranteed, that the string is quoted!

We've thought about
; : > < | *
and so on, but we can't figure out what character would be save to use, without side effects and platform independent (and hopefully not allowed in paths).
>
e.g will redirect stdout,
;
is the command separator on POSIX ect.

Any ideas what character we can use?

Answer

The best solution for us was using a platform depependent separator:

  • Windows: ;

  • Unix: :

A bit tricky to document, but a clean and save solution.

Comments