Thanks.  shlex.quote() is designed to make the string usable directly in shell, 
like so:

% lxc exec x1 bash
root@x1:~# lsb_release -rd
Description:    Ubuntu 16.04.6 LTS
Release:        16.04
root@x1:~# python3
Python 3.5.2 (default, Apr 16 2020, 17:47:17) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shlex
>>> def shlex_quote(v):
...     return "'" + v.replace("'", "\'\"\'\"\'") + "'"
... 
>>> value="SanDisk'"
>>> value
"SanDisk'"
>>> shlex.quote(value)
'\'SanDisk\'"\'"\'\''
>>> shlex_quote(value)
'\'SanDisk\'"\'"\'\''
>>> print(shlex.quote(value))
'SanDisk'"'"''
>>> 
root@x1:~# echo 'SanDisk'"'"''
SanDisk'

-- 
https://code.launchpad.net/~raharper/curtin/+git/curtin/+merge/382993
Your team curtin developers is requested to review the proposed merge of 
~raharper/curtin:fix/udevadm-info-shlex-quote into curtin:master.

-- 
Mailing list: https://launchpad.net/~curtin-dev
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~curtin-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to