在do shell脚本中间设置命令 [英] Set command in the middle of do shell script

查看:132
本文介绍了在do shell脚本中间设置命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试制作一个将所选文件复制到预定目录的简单应用程序,只有在shell脚本中设置该变量时,该变量才不起作用.我想知道是否有一种表达复制或移动命令以使其生效的方法.脚本在下面.

I have been attempting to make a simple application that copies a selected file to a predetermined directory, only the variable does not work when set in a shell script. I was wondering if there is a way to phrase the copy or move command to allow it to take effect. The script is below.

set filepath to POSIX path of (choose file with prompt "Chose your file")
delay
do shell script "cp " & filepath & " ~/Library/Application Support/"

推荐答案

它不起作用,因为必须转义路径中的空格字符,最可靠的方法是使用quoted form of.

It does not work because space characters in paths must be escaped, the most reliable way is to use quoted form of.

path to application support folder from user domain是当前用户的应用程序支持文件夹的相对路径.

path to application support folder from user domain is the relative path to the current user's application support folder.

set applicationSupportFolder to POSIX path of (path to application support folder from user domain)
set filepath to POSIX path of (choose file with prompt "Chose your file")
do shell script "cp " & quoted form of filepath & space & quoted form of applicationSupportFolder

这篇关于在do shell脚本中间设置命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆