我有将多个文件合并为一个的工具:
totool=""test file1.gam" "test file2.gam" "test fileN.gam""
tool $totool outfile.wrl
Run Code Online (Sandbox Code Playgroud)
问题是工具将空间识别为文件分隔符,"test file1.gam"将被视为两个文件.当我尝试做双引号变量参数时:
tool "$totool" outfile.wrl
Run Code Online (Sandbox Code Playgroud)
程序尝试打开单个文件"test file1.gam test file2.gam test fileN.gam"而不是多个文件.
我试图绕每个文件名转义双引号:
totool=""\"test file1.gam\"" "\"test file2.gam\"" "\"test fileN.gam\"""
Run Code Online (Sandbox Code Playgroud)
但程序识别转义双引号作为文件名的一部分:无法打开文件'"test file1.gam""test file2.gam""test fileN.gam"'进行阅读
.gam文件的数量是可变的,$ totool是在循环中定义的.
有什么建议?
您应该使用数组来保留包含空格的参数,如下所示:
totool=( "test file1.gam" "test file2.gam" "test fileN.gam" )
tool "${totool[@]}" outfile.wrl
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
164 次 |
| 最近记录: |