防止在 ksh 脚本中解析通配符
我正在读取文件名列表:
*.txt *.xml
这些文件名以空格分隔。我将其读入 ksh 脚本中的变量中,并且希望能够在将它们放入 find 命令之前对其进行操作。问题是,一旦我对变量执行任何操作(例如,将其分解为数组),* 就会解析为脚本目录中的文件名。我想要的是 *.txt 保持不变,这样我就可以将其放入我的 find 命令中。
我该怎么做?不幸的是,我在工作,不能只使用 perl 或其他语言。
I am reading in a list of file names:
*.txt *.xml
which are space delimited. I read this into a variable in my ksh script, and I want to be able to manipulate it before putting each of them into a find command. The problem is, as soon as I do anything with the variable (for instance, breaking it into an array), the * resolves into filenames that are in my script's directory. What I want is for the *.txt to remain unchanged, so I can put that into my find command.
How do I do this? Unfortunately, I'm at work and can't just use perl or some other language.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
set -f
关闭 ksh 中的通配符,因此 * 和 ?字符不会扩展(通配)。
set -f
turns off globbing in ksh, so * and ? characters are not expanded (globbed).
有什么问题吗
? 。否则你必须向我们展示更多你的问题。也许编辑您的帖子以包含一个说明您的问题的小测试用例,以及所需的输出或中间值。
what's wrong with
? . Else you have to show us more of your issues. Maybe edit your post to include a small test case that illustrates your problem, plus the desired output or intermediate values.