Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Unix&Linux>>quoting string with single quotes inside?

quoting string with single quotes inside?

rv8
04-01-2005, 08:43 AM
I'm trying to create an alias that I can use in my zsh shell. I want the alias to expand to:

osascript -e 'tell application "OmniWeb" of machine "eppc://PowerMac.local" to quit'

The normal alias syntax is:

aliasname='command_to_run'

But, the command I want to run has single quotes in it, so that fouls up the quoting. This must be a fairly common problem, so there has to be a good solution. I've looked at the zsh docs online, but I haven't found anything that helps, although I could easily have seen it and not understood it. Googling has also led me to many incomprehensible pages on quoting.

I eventually wrote a shell script instead of using an alias.

How should I do this as an alias?

Thanks,

ajp
04-01-2005, 05:12 PM
try a function instead.
omniQuit (){
osascript -e 'tell application "OmniWeb" of machine "eppc://PowerMac.local" to quit'
}

rv8
04-02-2005, 05:41 AM
try a function instead.


Thanks for the info. I'm on the road today, so I can't try it. I'll give it a go tomorrow.

darkpaw
04-02-2005, 04:44 PM
Escape the single quotes. Just put a \ in front of each single quote within the outer quotes, i.e.:

aliasname='osascript -e \'tell application "OmniWeb" of machine "eppc://PowerMac.local" to quit\''

Might work...

ajp
04-02-2005, 05:16 PM
it seems zsh follows similar expansion rules to bash, so escaping while in single quotes won't produce the desired results. you could try omniQuit="osascript -e 'tell application \"OmniWeb\" of machine \"eppc://PowerMac.local\" to quit'"
but i don't know much about zsh. it seems the function route mentioned above would maintain readability.

rv8
04-02-2005, 05:29 PM
Escape the single quotes. Just put a \ in front of each single quote within the outer quotes, i.e.:

aliasname='osascript -e \'tell application "OmniWeb" of machine "eppc://PowerMac.local" to quit\''

Might work...This gives the following complaint in Terminal when I start a new session:
/Users/my_short_name/Library/init/zsh/aliases.mine:38: unmatched 'I had already tried several variations escaping the single quotes before posting here, and none of them worked. Maybe there is a way to solve the problem with backslashes, but I wasn't smart enough to find it.


try a function instead.
omniQuit (){
osascript -e 'tell application "OmniWeb" of machine "eppc://PowerMac.local" to quit'
}

This works perfectly. Thanks.

rv8
04-02-2005, 05:38 PM
it seems zsh follows similar expansion rules to bash, so escaping while in single quotes won't produce the desired results. you could try omniQuit="osascript -e 'tell application \"OmniWeb\" of machine \"eppc://PowerMac.local\" to quit'".

This works. I'm not sure whether I'll use an alias or function. The little decisions are the hardest :)

Thanks for the education.


 

TOP

Windows Server Outsell
Unix Signals And C++ E

For more info

Unix Signals And C++ E
Windows Server Outsell
ssh setup for password
Bash script does not w
esc code 
ARD send unix command 
question about binarie
Scanning mail 
Issuing multiple comma
How do I install Linux

News Archive

/etc/hosts? 
Manually Start a Start
mounting missed hard d
Using Netinfo in Singl
darwin/bsd login probl
system_profiler and fi
Send mail from script 
mounting a drive 
OS X disk first aid ha
system.log shows steal

Related stories:

Bash script does not work!
esc code
ARD send unix command question
question about binaries
installing Libusb
Issuing multiple commands through SSH
ssh setup for passwordless login

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics