如何在msys2上的路径中转义空格?

时间:2017-07-19 11:43:20

标签: msys2

我想调用C:\Program Files (x86)\Leela\Leela0100.exe并传递一个文件名:

#!/bin/bash -x

BASE="c:/Users/supreme"
DROPBOX="$BASE/Dropbox"

DOWNLOADS="$BASE/Downloads"

cd $DOWNLOADS
SGF=`ls -th *.sgf | head -1`

GAMES="$DROPBOX/Baduk/Games"

mv $SGF $GAMES

LEELA='c://Program Files (x86)//Leela//Leela0100.exe'

cd $GAMES
$LEELA $SGF

但是,在MSYS2下通过bash -x toleela.sh调用我的脚本会产生错误:

c:\Users\supreme\Dropbox\Programming>bash -x toleela.sh 
bash -x toleela.sh 
+ BASE=c:/Users/supreme
+ DROPBOX=c:/Users/supreme/Dropbox
+ DOWNLOADS=c:/Users/supreme/Downloads
+ cd c:/Users/supreme/Downloads
++ ls -th '9001447-269-Winggo-princepawn (1).sgf' 9429961-080-princepawn-RyanBLee.sgf
++ head -1
+ SGF=9429961-080-princepawn-RyanBLee.sgf
+ GAMES=c:/Users/supreme/Dropbox/Baduk/Games
+ mv 9429961-080-princepawn-RyanBLee.sgf c:/Users/supreme/Dropbox/Baduk/Games
+ LEELA='c://Program Files (x86)//Leela//Leela0100.exe'
+ cd c:/Users/supreme/Dropbox/Baduk/Games
+ c://Program Files '(x86)//Leela//Leela0100.exe' 9429961-080-princepawn-RyanBLee.sgf
toleela.sh: line 18: c://Program: No such file or directory

1 个答案:

答案 0 :(得分:3)

正如您在IRC上已经指出的那样,您在脚本的最后一行(也在其他行上)的变量扩展周围缺少引号。

"$LEELA" "$SGF"

可执行路径中的双正斜杠(//)不正确。请改用单正斜杠(/或双反斜杠(\\。编辑:反斜杠更复杂,所以坚持前进。