【问题标题】:Applescript shell script to folder with spaceApplescript shell脚本到带有空格的文件夹
【发布时间】:2018-10-15 11:34:55
【问题描述】:

我正在尝试将文本文件写入名称中包含空格的文件夹。例如:文件夹 2

写入文件夹的第一个脚本正常工作 写入文件夹 2 的第二个脚本无法正常工作。

编辑: 如果我对路径进行硬编码,我尝试在路径周围使用单引号并且它可以工作。有没有办法在不丢失 ~ 符号的情况下写入文件夹?

    --this works
   do shell script "echo " & "the text" & " >> ~/Desktop/folder/text.txt"

    --this does not work
   do shell script "echo " & "the text" & " >> ~/Desktop/folder 2/text.txt"

【问题讨论】:

    标签: shell applescript


    【解决方案1】:

    这将起作用:

    do shell script "echo " & "the text" & " >> ~/Desktop/folder\\ 2/text.txt"
    

    注意:当使用~ 时,与$HOME 相同,在do shell script 中并且在路径名 中有一个空格,使用一个双反斜杠\\ 转义空格,并且不要引用包含~路径名。在bash 中,空格 只需要一个反斜杠\ 来转义空格

    这也有效:

    do shell script "echo " & "the text" & " >> \"$HOME/Desktop/folder 2/text.txt\""
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多