如何将 AppleScript 中的变量传递给 shell 命令?
How do I pass a variable from AppleScript to a shell command?
到目前为止我有:
do shell script {var}
"if [[ ! -e /$var/ ]]; then
mkdir -p $var
fi"
我收到 "Command not found"
的错误
我知道我需要逃避一些事情,只是不确定去哪里。
Var 需要传递给shell 命令,如果目录不存在则在指定的文件夹中创建目录。
您只需要,例如:
set var to "/path/to/directory/subdirectory"
do shell script "mkdir -p " & var's quoted form
您不需要测试它是否已经存在,因为使用 -p
选项 和 mkdir
命令.
来自 mkdir
的手册页:
-p Create intermediate directories as required. If this option is not specified, the full path
prefix of each operand must already exist. On the other hand, with this option specified, no
error will be reported if a directory given as an operand already exists. Intermediate
directories are created with permission bits of rwxrwxrwx (0777) as modified by the current
umask, plus write and search permission for the owner.
到目前为止我有:
do shell script {var}
"if [[ ! -e /$var/ ]]; then
mkdir -p $var
fi"
我收到 "Command not found"
的错误我知道我需要逃避一些事情,只是不确定去哪里。
Var 需要传递给shell 命令,如果目录不存在则在指定的文件夹中创建目录。
您只需要,例如:
set var to "/path/to/directory/subdirectory"
do shell script "mkdir -p " & var's quoted form
您不需要测试它是否已经存在,因为使用 -p
选项 和 mkdir
命令.
来自 mkdir
的手册页:
-p Create intermediate directories as required. If this option is not specified, the full path prefix of each operand must already exist. On the other hand, with this option specified, no error will be reported if a directory given as an operand already exists. Intermediate directories are created with permission bits of rwxrwxrwx (0777) as modified by the current umask, plus write and search permission for the owner.