linux - BASH 文件空间

标签 linux bash file scripting path

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

#!/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/

相关文章:

bash - 自删除 bash 脚本

linux - 在 Linux 中使用 sed 替换字符串

VB.Net:按行搜索Word文档

python - 两个文件在行方面的区别

linux - PCI 驱动程序(request_mem_region 失败)

linux - 在 Perl 中是否有等同于 `tail -f` 的东西?

linux - 可视化 strace 输出

linux - ansible 卡在 "sudo yum install"' 步骤

linux - 如何使用 find 复制和删除保持相同子目录结构的扩展

python - Python Mutagen覆盖mp3专辑封面