2

使用growlnotify如何从命令行显示多行文本?

Slash-n -\n像这样似乎不起作用:

growlnotify -t title -m "messageline1\nmessage2"

我只是收到一条消息messageline1\nmessage2

4

2 回答 2

2

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.

于 2011-11-14T23:28:53.030 回答
0

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"
于 2012-07-12T13:15:50.513 回答