How can I trigger brace expansion inside a script?

别等时光非礼了梦想. 提交于 2019-12-31 01:51:12

问题


I'm writing a script which needs to use the shell's brace expansion, but nothing I've tried works. For (a contrived) instance, say I have a variable containing the string

thing{01..02}

and I (obviously) want to expand it to

thing01 thing02  

from inside the script, how can I do that?

(For anyone who assumes this is a duplicate of this other question, please read them more carefully. That question is regarding working from the shell, not a shell script, and doesn't require the ability to expand arbitrary expressions.)


回答1:


$ echo thing{01,02}

thing01 thing02



回答2:


Make sure that braceexpand is turned on with set -o braceexpand.



来源:https://stackoverflow.com/questions/7081266/how-can-i-trigger-brace-expansion-inside-a-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!