bash脚本命令的字符串连接
我正在尝试在我的bash脚本命令的字符串连接,bash,Bash,我正在尝试在我的~/.bashrc表单中写入别名: alias a="foo; osascript -e 'tell application "Terminal" to do script "bar"; baz" (其中,bar将在新的终端窗口中启动,如所示),但该字符串看起来不会被解析。我尝试了字符串插值(${str}),但问题似乎无法通过这种方式解决。令人惊讶的是,字符串似乎可以正常工作。只要它在一行上,Bash就不会像您期望的那样终止双引号字符串 更新:正如Ignacio指出的,写入的字
~/.bashrc
表单中写入别名:
alias a="foo; osascript -e 'tell application "Terminal" to do script "bar"; baz"
(其中,
bar
将在新的终端窗口中启动,如所示),但该字符串看起来不会被解析。我尝试了字符串插值(${str}
),但问题似乎无法通过这种方式解决。令人惊讶的是,字符串似乎可以正常工作。只要它在一行上,Bash就不会像您期望的那样终止双引号字符串
更新:正如Ignacio指出的,写入的字符串不会保留其中的双引号。也就是说:
# 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
令人惊讶的是,该字符串似乎可以正常工作。只要它在一行上,Bash就不会像您期望的那样终止双引号字符串 更新:正如Ignacio指出的,写入的字符串不会保留其中的双引号。也就是说:
# 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
不。但它也不会引用这些文章。但是它也不会引用那些片段。那可能是
~/.bashrc
(没有下划线)。哦,谢谢。在Ruby中工作太多了。更正。这可能是~/.bashrc
(没有下划线)。噢,谢谢。在Ruby中工作太多了。更正。