使用growlnotify
如何从命令行显示多行文本?
Slash-n -\n
像这样似乎不起作用:
growlnotify -t title -m "messageline1\nmessage2"
我只是收到一条消息messageline1\nmessage2
使用growlnotify
如何从命令行显示多行文本?
Slash-n -\n
像这样似乎不起作用:
growlnotify -t title -m "messageline1\nmessage2"
我只是收到一条消息messageline1\nmessage2
The intended escaped newline is not interpreted as such by growl - it's just treated as a literal slash, followed by an 'en'.
You can get the shell to insert a newline in the string this way:
growlnotify -t title -m "messageline1"$'\n'"message2"
See (e.g.) Unix command sh:
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specifed by the ANSI C standard.
echo
我发现在脚本中使用一个小函数和's-e
选项更容易且更具可读性:
mynotify () {
for m in "$@"; do
local msg="$msg\n$m"
done
echo -e "$msg" | growlnotify -t "My Title"
}
mynotify "This is line 1" "Line 2" "The 3d line ends with an extra newline\n" "Line 4"