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,
try a function instead.
omniQuit (){
osascript -e 'tell application "OmniWeb" of machine "eppc://PowerMac.local" to quit'
}
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...
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.
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.
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.