views:

80

answers:

2

I'm trying to write an alias in my ~/.bashrc of this form:

alias a="foo; osascript -e 'tell application "Terminal" to do script "bar"; baz"

(where bar launches in a new Terminal window, as per this question) but this string doesn't look like it will parse. I tried string interpolation (${str}), but the problem seems to be unsolvable that way.

A: 

Surprisingly, the string appears to work fine as written. As long as it's on one line, Bash doesn't terminate the double-quoted string the way you'd expect.

Update: As Ignacio points out, the string as written doesn't preserve the double quotes within it. To wit:

# Good:
a="foo; osascript -e 'tell application \"Terminal\" to do script \"bar\"'; baz"
echo $a
> foo; osascript -e 'tell application "Terminal" to do script "bar"'; baz

# Not so good:
b="foo; osascript -e 'tell application "Terminal" to do script "bar"'; baz"
echo $b
> foo; osascript -e 'tell application Terminal to do script bar'; baz
Trevor Burnham
Nope. But it won't quote those pieces either.
Ignacio Vazquez-Abrams
+1  A: 
alias a="foo; osascript -e 'tell application \"Terminal\" to do script \"bar\"'; baz"
Ignacio Vazquez-Abrams