2011-06-14 65 views
0

嗨,但似乎如果我的字符串中有空格,它将无法正常工作。我的整个脚本是在这里:BASH文件空间

#!/bin/bash 
echo $#; echo [email protected] 
MoveToTarget() { 
    #This takes to 2 arguments: source and target 
     echo ""$1" "$2"" 
    cp -rf "$1"/* "$2" 
    rm -r "$1" 
} 

WaitForProcessToEnd() { 
    #This takes 1 argument. The PID to wait for 
    #Unlike the AutoIt version, this sleeps 1 second 
    while [ $(kill -0 "$1") ]; do 
      sleep 1 
    done 
} 

RunApplication() { 
    #This takes 1 application, the path to the thing to execute 
    open "$1" 
} 

#our main code block 
pid="$1" 
SourcePath="$2" 
DestPath="$3" 
ToExecute="$4" 
WaitForProcessToEnd $pid 
MoveToTarget "$SourcePath" "$DestPath" 
RunApplication "$ToExecute" 
exit 

请注意,我试图像$ DestPath变量与不周围引号,没有运气。这段代码是通过Python脚本运行的,当参数传递时,引号就在它们周围。我感谢任何帮助!

编辑:(Python脚本)

bootstrapper_command = r'"%s" "%s" "%s" "%s" "%s"' % (bootstrapper_path, os.getpid(), extracted_path, self.app_path, self.postexecute) 
shell = True 
subprocess.Popen(bootstrapper_command, shell=shell) 
+0

你可以显示Python脚本吗? – 2011-06-14 21:06:05

+3

一个通用的调试提示,使用'#!/ bin/bash -x'运行它,然后每个有值的变量都会在脚本执行时回显给stdout。 – 2011-06-14 21:14:18

+0

你可以'echo $#; echo $ @'在脚本的顶部?这可能会有一点点亮。 – pilcrow 2011-06-14 21:17:20

回答

2

猛砸引号语法,而非文字。像往常一样,Greg's Wiki有你想要的最好的解释。

+0

那里非常有用的信息。如果可以的话,我也会给格雷格+1 – kris 2012-01-22 18:21:39

0

尝试删除*,递归复制不需要。

cp -rf "$1"/* "$2" 

到:

cp -rf "$1/" "$2" 

我觉得通配符是毁了你的报价这是保护你从空间中的文件名。