Westrock
Westrock

Reputation: 169

Linux: How to display message when running command?

Is it possible to make the command line display a message when running a command? I have used shell scripts to intercept command names and display messages and then launch the command, but I was wondering if something more "native".

Something like an if statement in the bashrc that says if xyzcommand then echo message and run xyz command.

As an example I'm thinking of something along the lines of user runs "xeyes" and a message appears that says "watching you". But NOT after the program has executed, it needs to display while program is running.

[user@computer bin]$ xeyes 
watching you

Upvotes: 0

Views: 2792

Answers (2)

Westrock
Westrock

Reputation: 169

Thanks to William Pursell for the hint!

I set a function in the /etc/bashrc

function xeyes {
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!"
echo "!!!!! Watching You !!!!!"
echo "!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
/usr/bin/xeyes     
}

Very important part here! DO NOT just put the command name in the function if the function is meant to have the SAME NAME!

Otherwise what happens is that the bashrc function does the echo and then runs the command, but the bashrc then redirects the command name back to the function itself and echos the message again.....creating an endless loop. If you want to have the function be the same name as the command then you need to put the full path (or something referencing the full path) of the command in the function as seen above.

Now when I type xeyes, I get the message as well. But when I type "which xeyes" I still get the useful /usr/bin/xeyes message.

Upvotes: 0

Kerb
Kerb

Reputation: 140

you can run two commands at the same time, by running them in the background with & example: your-script.sh & popup_message_programm &

to display a message you can use in example Libnotify https://wiki.archlinux.org/index.php/Desktop_notifications

Upvotes: 1

Related Questions