single quote escaping in applescript/shell

后端 未结 3 880
无人共我
无人共我 2021-02-10 08:35

I\'m trying to process this shell script in applescript, but it keeps saying error EOF, because of the single quote in the folder name.

do shell script \"cp -R \         


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-02-10 09:16

    Always use quoted form of when using arbitrary data as an argument to an command. This will always quote the value even if it doesn't need to be quoted but it's better safe than sorry. When you have a string single quoted, you can only unquote (turn substitution mode back on) with another quote. Unlike AppleScript strings, you can't escape characters inside single quoted strings. So you need to turn substitution mode on, escape a quote and then turn substitution mode back one. For instance "Joe's car" should be quoted as "'Joe'\\''s car'". It's a quoted string "Joe" + escaped quote character + quoted string "s car". But like I started you should use quoted form of, quoted form of "Joe's car" will return "'Joe'\\''s car'"

    Your command using quoted form will look like:

    do shell script "cp -R " & quoted form of a & space & quoted form of (d & "/My 'Folder/java/")
    

提交回复
热议问题