如何在以下 bash 代码中拆分长 valueX 字符串?
case "$1" in
value1|value2|value3|...........more values..................| valueN)
some_processing "$@"
;;
...
esac
我正在寻找拆分成单独的行。 M.b.喜欢:
VAL+=value1
VAL+=value2
....
最佳答案
来自手册页:
A case command first expands word, and tries to match it against each pattern in turn, using the same matching rules as for path‐name expansion[.]
换句话说,它是一个 glob 模式,而不是正则表达式。因此,您可以在模式标记之间使用 IFS。例如:
case "$1" in
value1 | \
value2 )
:
;;
esac
请注意,您必须使用反斜杠对续行进行转义,这与管道符号将自动续行的通常情况不同。除此之外,您可以按照提示符下的方式拆分行。
关于string - 如何将很长的案例模式拆分成多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10884542/