Reputation: 1449
I have a text file b.txt with the following text:
notify-send -i gtk-info "How Are You" -h string:x-canonical-private-synchronous:anything
I have a shell script with the following code:
#!/bin/sh
while true;
do if [ -s b.txt ]
then
value="$(cat b.txt)"
exec $value
sleep 0.1
fi
done
When I run the script it throws the following error and notification is not displayed:
Invalid number of options.
But when the text file contains the command with just two words like this:
notify-send -i gtk-info "Hows You" -h string:x-canonical-private-synchronous:anything
the notification is displayed perfectly.
This issue is happening only when I execute notify-send through a shell script. How do I display a notification with a message having any number of words?
Upvotes: 0
Views: 1248
Reputation: 189937
exec
is entirely the wrong thing to use here. Maybe try
#!/bin/sh
while true;
do
if [ -s ./b.txt ]
then
. ./b.txt
sleep 0.1
fi
done
But running this in a tight loop seems like an odd thing to want to do, and executing a file of unknown provenance is dubious at best. Are you sure this text file will always contain exactly the contents you expect and cannot be modified by anyone? Why is this command being put in a separate file in the first place?
Upvotes: 2