嗨,但似乎如果我的字符串中有空格,它将无法正常工作。我的整个脚本是在这里: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)
你可以显示Python脚本吗? – 2011-06-14 21:06:05
一个通用的调试提示,使用'#!/ bin/bash -x'运行它,然后每个有值的变量都会在脚本执行时回显给stdout。 – 2011-06-14 21:14:18
你可以'echo $#; echo $ @'在脚本的顶部?这可能会有一点点亮。 – pilcrow 2011-06-14 21:17:20