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

时间:2015-04-19 07:06:49

标签: bash 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想要的转义空格或文字引用?

我在./运行时遇到的错误是: 217:218:语法错误:预期表达式但发现未知令牌。 (-2741)

1 个答案:

答案 0 :(得分:1)

你需要在字符串周围加上引号:

set f to "$BACKUPSTORE"

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