Search code examples
stringbashshnotify-send

ShellScript parsing a sting variable to notify-send


I have never seen this anywhere in my search I am making a script to see if I can send a string variable to notify-send so far

$MESSAGE='Hello world!'
notify-send "`$MESSAGE`" -t 1

will trow

Hello command not found

and

notify-send $MESSAGE -t 1

sends a too many argument error

so is there a way to do that?


Solution

  • Try this:

    MESSAGE='Hello world!'
    notify-send "$MESSAGE" -t 1
    

    We declare a variable using NAME=VALUE in bash. There's no $ sign before the variable name. Then you enclose variable value obtained by using $ character using ". The ` character is used as a command substitution, same as $(...).When you write "`$MESSAGE`", you tell you bash to execute command named Hello with argument world!. As such command does not exists, your bash returns Hello command not found.