将带空格的文件名传递给 shell 脚本

ead*_*ter 10 filenames

shellscript 非常简单:

retroarch $* -c /tmp/retroarch/Data/retroarch/gambatte.cfg
Run Code Online (Sandbox Code Playgroud)

(“retroarch”是另一个shellscript)

如果传递的文件名包含空格,则失败:

RetroArch [ERROR] :: Could not read ROM file.
Run Code Online (Sandbox Code Playgroud)

fro*_*utz 13

使用引号。

代替

yourcommand some file.name
Run Code Online (Sandbox Code Playgroud)

yourcommand "some file.name"
Run Code Online (Sandbox Code Playgroud)

使用变量时,也要引用它们。

yourcommand "$filename"
yourcommand "$@"
...
Run Code Online (Sandbox Code Playgroud)

  • 已经试过了,但没有用! (2认同)