嗨但似乎如果我的字符串中有空格,它将无法正常工作。我的整个脚本都在这里:
#!/bin/bash
echo $#; echo $@
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 :(得分:2)
Bash引号是语法,而不是文字。像往常一样,Greg's Wiki有你想要的最优秀的解释。
答案 1 :(得分:0)
尝试删除*,递归复制不需要它。
cp -rf "$1"/* "$2"
为:
cp -rf "$1/" "$2"
我认为通信操作破坏了你的引用,保护你免受文件名中的空格的限制。