arrays - 如何在bash数组元素中转义引号
问题描述
我想像这样创建一个数组
array=(
"element1 with "quoted string""
"element2 without double quoted string"
"element3"
)
运行代码后输出
echo ${array[0]}
element1 with quoted.
我正在尝试在 echo 输出中包含引号。我该怎么做呢?
解决方案
要么使用单引号,
array=(
'element1 with "quoted string"'
...
)
或转义文字双引号:
array=(
"element1 with \"quoted string\""
...
)
您的第一个嵌套引号关闭了开头引号,但quoted
仍被视为当前单词的一部分。数组的下一个元素在string
其末尾附加了一个空字符串。
推荐阅读
- javascript - 如何推进猫鼬搜索?
- mule4 - 比较两个变量并计算第三个变量并将其附加到 mule4 中的现有变量
- sql - DB2,按年份分组和求和,其中年份是列值
- python - Python 在使用 fast_executemany = True 和 Sybase 表插入时因“字符串数据,右截断”而崩溃
- javascript - 电报应用程序从输入消息中删除多个单词
- drupal - Drupal entity查询多种节点类型并加入
- spring-boot - 如何阻止 IntelliJ IDEA 调试器通过 Spring Boot 源代码?
- css - 如何填充 Stack Chakra-UI 中的剩余空间?
- javascript - 防止 NavLink 中另一个元素的 NavLink 行为
- vba - 邮件发送后如何执行代码?