您好,但是如果我的字符串中有空格,它似乎无法正常工作。我的整个脚本在这里:
#!/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)
最佳答案
Bash 引号是句法的,而不是字面的。 Greg's Wiki ,像往常一样,有您所希望的最出色的解释。
关于linux - BASH 文件空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6350108/