我有一大组文件名中带有“:”的文件。当我在交互式 shell 中时,输入“\”然后按 Tab 键可以将它们识别为命令的有效输入,但在 shell 脚本中则不然。
我已经尝试过
less file:name.txt
less file\:name.txt
less 'file\:name.txt
less 'file:name.txt'
并且它未被识别为有效文件。
但是,在交互式命令行上,我输入 less,然后输入第一个文件,然后输入\,然后按 TAB 键,然后一切正常...
如何在 shell 脚本中执行此操作?
最佳答案
使用双引号:
less "file:name.txt"
Bash 将双引号内的值识别为完整字符串。
如Using quotes to include spaces and characters in filenames中所示:
If you want to work with files with spaces or special characters in the filename, you may have to use quotes.
关于macos - 如何在shell脚本中处理文件名中的冒号 ":",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22297728/