有 Bash 来解析多个 space-contained 由转义字符连接的单词 \
Have Bash to parse multiple space-contained words connected by escape char \
如何在一个字符串中,用最简单的方式(1-2 commands/lines) ?
s="English phrases must be understood are as\ well, even\ if, as\ such"
如何在几个变量中实现(或用引号对而不是双引号括起来):
a="English"
b="phrases"
c="must"
d="be"
e="understood"
f="are"
g="as well,"
h="even if,"
i="as such"
或者作为s变量本身的数组等,请指点正确路径
read -a arr <<< "$s"
read
依赖于 IFS
拆分词。如果您修改了该变量,
在上面的命令前添加 IFS=' '
。
$ for i in "${arr[@]}"; do echo "$i"; done
English
phrases
must
be
understood
are
as well,
even if,
as such
如何在一个字符串中,用最简单的方式(1-2 commands/lines) ?
s="English phrases must be understood are as\ well, even\ if, as\ such"
如何在几个变量中实现(或用引号对而不是双引号括起来):
a="English"
b="phrases"
c="must"
d="be"
e="understood"
f="are"
g="as well,"
h="even if,"
i="as such"
或者作为s变量本身的数组等,请指点正确路径
read -a arr <<< "$s"
read
依赖于 IFS
拆分词。如果您修改了该变量,
在上面的命令前添加 IFS=' '
。
$ for i in "${arr[@]}"; do echo "$i"; done
English
phrases
must
be
understood
are
as well,
even if,
as such