single quote escaping in applescript/shell

后端 未结 3 882
无人共我
无人共我 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:03

    The problem arises because you have that tick in the filename of course, on the terminal commandline you would use a tick - double-tick tick - double-tick tick sequence to present it.

    (From the terminal below)

    729$ echo 'My '"'"'Java Folder'
    My 'Java Folder
    

    In Applescript, and your command line, it becomes even more complicated, I recommend you echo your commandline, until you get back what you expect.

    set res to (do shell script "echo 'My '\"'\"'Java Folder'")
    log res
    --> (*My 'Java Folder*)
    

    I think you'll have to start out with that, and reconstruct how you escape the rest of the commandline around it, if it can't be just plugged in as it is.

    You should also remove single quotes for entities, that doesn't need them, (no spaces). That way your commandline will become easier to both edit and read.

提交回复
热议问题