Couldn't help noticing the shell scripting again ...
Okay, here is a blog by blow of the snappy shell script.
> #!/bin/bash
Yeah, well, it can be tolerated. The script actually contains a couple of bashisms, although they could be avoided; and anyway, if you are on Ubuntu, you are, shall we say, fairly likely to have a copy of Bash on your system.
> a=`ps -aef | grep -i xcompmgr | awk ' {if ($8 == "xcompmgr"){printf "2"}} '`
Argh. Here's how to do that.
a=`ps -aeof | awk '($8 == "xcompmgr") { printf "2" }'`
I suspect the "2" was supposed to be "$2" but it doesn't matter here, because the result is thrown away ... Also I suspect the guy didn't know about print so that's why he used printf; not that it matters much.
> if [[ $a = "" ]]
> then
So here's the bashism. You just have to wonder if it's necessary. The classical Bourne idiom for this would be to use case (or test, but it was an external process in historical times, so case is preferred):
case $a in
'') <
> ;;
*) <>;;
esac
More below.
> yourcommand &
> killall gnome-panel
I'm sure if you have other users on your system they will not be happy if you kill their gnome-panels. Let's just hope you don't run this as root by mistake. Fixing this is left as an exercise. (Hint: Use less obtuse ps options to get a listing only of your own processes -- makes sense for other reasons too. And/or run another ps to get the PIDs of your gnome-panels and only yours. And/or abort if you are running as root.)
> else
> kill -9 `ps -aef | grep -i xcomp | awk ' {if ($8 == "xcompmgr"){printf $2}} '`
> killall gnome-panel
> fi
Erm, so here we do the nasty "ps | did not read the faq so kill me" again? Again? Why not use the result in $a from the previous run? (Ah, because it was incompetently discarded?)
Also, never never ever use kill -9 in a script unless you really really know what you are doing.
We assume that the guy got tired of copy-pasting his own code (always a sign of a high level of goodness) and that the grep xcomp (pro grep xcompmgr) is not there for any particular reason.
kill $a
If you kill gnome-panel regardless of the outcome of the if/else, why do you have it twice inside the if, instead of once, outside?