在 AppleScript 中具有 HEREDOC 的 Bash 脚本中扩展变量

expanding variables inside an Bash script that has a HEREDOC in AppleScript

我有这个简单的代码:

#!/bin/bash

# Where are we going to store these files?
BACKUPSTORE="$HOME/Library/Application\ Support/Evernote-Backups"
/bin/echo "BACKUPSTORE: $BACKUPSTORE"
/bin/mkdir -p "$BACKUPSTORE"
/usr/bin/cd "$BACKUPSTORE"

osascript <<END
-- PURPOSE: Export all notes in Evernote to an ENEX file so that
-- the notes can be backed up to an external drive or to the cloud

-- Change the path below to the location you want the notes to be exported
set f to $BACKUPSTORE

with timeout of (30 * 60) seconds
    tell application "Evernote"
        -- Set date to 1990 so it finds all notes
        set matches to find notes "created:19900101"
        -- export to file set above
        export matches to f
    end tell
end timeout

-- Compress the file so that there is less to backup to the cloud
set p to POSIX path of f
do shell script "/usr/bin/gzip " & quoted form of p
END

我想我遇到了一个错误:

set f to $BACKUPSTORE

或者可能在:

set p to POSIX path of f
do shell script "/usr/bin/gzip " & quoted form of p

如何使扩展工作,并处理文件路径中的空格并使用转义空格或 AppleScript 需要的文字引号?

当我 ./运行 时,我在 shell 中得到的错误是: 217:218:语法错误:需要表达式但发现未知标记。 (-2741)

您需要在字符串两边加上引号:

set f to "$BACKUPSTORE"

分配给 BACKUPSTORE 时,您也不需要转义空格,因为您的值在引号中。