1

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.

Community
  • 1
  • 1
Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196

2 Answers2

1
alias a="foo; osascript -e 'tell application \"Terminal\" to do script \"bar\"'; baz"
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

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
  • 76,828
  • 33
  • 160
  • 196