You are not logged in.
Hello, everyone, thanks in advance.
$ aa=$(brightnessctl)
$ notify-send "brightness" "$aa"
shows as I expect, multiple lines in one notification. But
$ brightnessctl | while read aa; do notify-send "brightness" "$aa"; done
shows multiple notifications instead of multiple lines in one notification, because brightnessctl command's output is multiple lines.
How can I solve this so that to show one notification and multiple lines in it?
Last edited by duyinthee (2023-03-02 08:14:40)
Offline
notify-send accepts multiline input just fine.
The problem is not with notify-send, but with the script. It does not pass multiple lines as the argument. It splits lines and invokes notify-send for each one separately.
The solution is… to not split them. You already provided the valid code yourself.
Last edited by mpan (2023-02-28 11:25:31)
Sometimes I seem a bit harsh — don’t get offended too easily!
Offline
Thanks for reply.
I now have this solution
#!/bin/dash
ptnt () {
msg=$(while read opt; do echo "$opt"; done)
notify-send -t 7000 "brightness" "$msg"
}
brightnessctl 2>&1 | ptnt
but I still have an issue to solve. What if I want to pip only stderr to notify-send (not stdout)?
How to pip only command not found error to notify-send in the following;
#!/bin/dash
ptnt () {
msg=$(while read opt; do echo "$opt"; done)
notify-send -t 7000 "brightness" "$msg"
}
brightnessctl 2>&1 | ptnt
bbbbbrightnessctl 2>&1 | ptnt
I tested changing this part 2>&1 in many forms, but not work.
Last edited by duyinthee (2023-03-02 02:37:02)
Offline
Do you want to display each LED info in separate notification? You can split brightnessctl output by empty lines, e.g.:
$ brightnessctl | awk -v RS='' '{printf $0"\0"}' | xargs -r0 -n1 notify-send
Offline
Since you are using dash, I can’t really help.
However, if redirection works the same as in bash, you did not redirect stdout to anywhere, so it is mixed with stderr. You need to redirect stdout to somewhere else. For example to “/dev/null” if it is not needed:
command 2>&1 >/dev/null
Sometimes I seem a bit harsh — don’t get offended too easily!
Offline
Do you want to display each LED info in separate notification?
How can I solve this so that to show one notification and multiple lines in it?
msg=$(while read opt; do echo "$opt"; done)
wtf…
notify-send -t 7000 "brightness" "$(brightnessctl 2>&1 1>/dev/null)"
Online
Thanks all for helpful replies. Yes,
2>&1 1>/dev/null
works perfect.
Offline