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开发者_C百科 tried string interpolation (${str}
), but the problem seems to be unsolvable that way.
alias a="foo; osascript -e 'tell application \"Terminal\" to do script \"bar\"'; baz"
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
精彩评论