Making a do shell script with " characters without exiting it

I have a do shell script with contains characters such as



here is one line from it

blocknum=printf %d "'\ bs=1 skip=2 count=1 2>/dev/null\"`

now the problem is, when I have it in a do shell script

do shell script “blocknum=printf %d "'\ bs=1 skip=2 count=1 2>/dev/null`”`"

Applescript thinks that it ends early because of the " and ’ characters.

any way around this?


Have you tried to escape the offending characters manually by putting // in front of them.?

Best Regards


how do you mean?

that I should do like this

lets pretend I have a terminal command that looks like this


and making a applescript out of it would be, from your instructions, like this:

do shell script "do//"what//“ever”

am I correct?
it still doesnt run, it still thinks the shell script ends after do//


Sorry for misguiding you, I was sure i entered backslashes not slashes!

I guess i didn’t see what keys I hit on the keyboard \ is the one to try, like a normal escape in the shell,
but you need one more, since AppleScript uses the [b][/b] as a special character.

I guess it was the bold quoting that made the trick (or not) :frowning:

Best Regards


Assuming this is the command you want to send to the command line:

blocknum=`printf %d "'\ bs=1 skip=2 count=1 2>/dev/null\`"`

The question becomes how do you enter that in applescript. In applescript the \ character is the escape character, so you have to put that in front of any double-quote character because your command text is between double-quotes in applescript. You have another problem though. You actually want to pass the \ character through to the command line as well. Applescript won’t pass that character through because it’s the escape character. So in essence you have to escape the escape character to pass it through.

Here’s how I would write it. You’ll see that I placed a \ character in front of all the " and \ characters in your original command.

set cmd to "blocknum=`printf %d \"'\\ bs=1 skip=2 count=1 2>/dev/null\\`\"`"
do shell script cmd

how to I combine several commands in one do shell script.

like this:

If I do this in terminal

cd Programs


it will list all my programs.

but with applescript:

do shell script “cd Programs”
do shell script “ls”

they are not run within the same shell, so it will list my boot drive because the cd is not still there.

how can I combine several commands like this?

oh and the code you made worked beutifully, thanks.

To run more than 1 command from the command line just separate them with a semicolon. So try this…

do shell script "cd /Applications; ls"


I think you should be aware of the different ways you actually can execute strings of commands from the shell.
That knowledge might ease what you are trying to achieve.

the semicolon is a command separator, like if you had entered return in the shell. I you want to consolidate the output of several shell commands into one result from the do shell script command, then you can do that by
surrounding the whole sequence with parenthesis like this:

[code]# Try this in the terminal window with some small reall files:
( echo “file one”;cat ;echo “file two” ; cat file.two ) |more

everything should be returned in the result of the “do shell script”[/code]

What you specifically wants:

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set theText to (do shell script "cd / ; ls ")
set theText to theText as text
set AppleScript's text item delimiters to astid
--display dialog theText

Best regards and hopes this helps.


Thanks, I learned some really useful stuff =D