我需要在字符串中嵌入单引号。如何通过Shell脚本实现?
示例输入:--connect jdbc:sqlserver:// XXXX:12; DatabaseName = S
输出:--connect'jdbc:sqlserver:// XXXX:12; DatabaseName = S'
此格式将始终保持不变。
答案 0 :(得分:1)
您可以使用以下内容:
echo "--connect jdbc:sqlserver://XXXX:12;DatabaseName=S" | sed "s| jdbc| 'jdbc|g;s|$|'|g"
答案 1 :(得分:0)
您也可以逃脱它们:
Traceback (most recent call last):
File "/home/pi/python/test.py", line 45, in <module>
token = generate_sas_token()
File "/home/pi/python/test.py", line 20, in generate_sas_token
signature = b64encode(HMAC(b64decode(KEY), sign_key, sha256).digest())
File "/usr/lib/python3.5/hmac.py", line 84, in __init__
self.update(msg)
File "/usr/lib/python3.5/hmac.py", line 93, in update
self.inner.update(msg)
TypeError: Unicode-objects must be encoded before hashing
输出'hello'