help with bash

set thetext to the clipboard
do shell script "echo "  & thetext 

Dont try to make sense of the script. Its a part of another script. Just note that I want the shell to process the clipboard for some reasons.

As I understand, there is some quoting (single and double quotes) issue which does not allow the shell to process the clipboard properly if the clipboard contains special characters like “&” or spaces or empty lines.
How to fix it?
I read this article:
http://tr.im/iYby
I know about osascript command and the “here” command(if applescript has more than one line) to write applescript code in bash but I dont think I will be able to first create a variable in applescript (“thetext” in the above example), and then process it with shell script (i.e. fix the quoting issue) so that shell script can use it.
(Also, i am not planning to call a bash file from applescript :))
Thanks.

Try this:


set cb to (the clipboard) as text
set qtdcb to quoted form of cb
set output to do shell script "echo " & qtdcb

Hi Martin,
Thanks a lot. Nice to see you again. :slight_smile:

I am actually piping the text into Quicksilver.
so i am using:

set cb to (the clipboard) as text
set qtdcb to quoted form of cb
set output to do shell script "echo " & qtdcb & "| qs"

If you copy this text from this page:

It fails again.

I guess the problem is related to QS, because the following script just works fine (after having copied the text snippet above into the clipboard):


set cb to (the clipboard) as text
set qtdcb to quoted form of cb
set output to do shell script "echo " & qtdcb & " | grep -c Pages"

the problem may be with quicksilver but it is regarding the " » " character. So what would be a workaround? (Somehow replace them with " > ").
Also, would it be possible to know which other characters are likely to have issues?

Many thanks, Jacques

How did you find this out?

Thanks for the info, Jacques. The script is such a nice way to test things.

Is there no workaround?
The only thing i could think of was to replace the commonly used Extended ASCII characters with similar looking Standard ASCII characters using applescript text delimiters before passing the clipboard to shell… For example replace,
" » " character with " >> ").

Thanks, Jacques