title: Bash-script to toggle espeak by keyboard shortcut
body: <p>To read a selected text in GUI out loud I use the command <code>xsel | espeak-ng -v mb-us3 -p3 -s135</code>.
  To stop it I use <code>killall -s STOP espeak-ng</code>.
  To start it again <code>killall -s CONT espeak-ng</code>.</p>
  <p>All 3 commands work, but the noob I am won't let me archive correct results. The problem is in the if- and case-statement I think. I assigned them to a keyboard shortcut.</p>
  <p>I want to manage this shellscript to toggle between read aloud and stopping the process of reading aloud if espeak-ng is already running. If it's not already running the bash should start it.</p>
  <pre><code>0 #!/bin/bash
  1 # Name: espeak-en.sh
  2 # Author: Karsten Zarth
  3 # Created: 2020-08-23
  4 # Description: Textselection in GUI is read aloud with english
  5 #              male voice with espeak-ng and mbrula
  6 #              if already reading: stop
  7 #              if stopped: continue
  8 # Modified: 2020-08-23
  9
  10 status=`ps -ef| grep espeak-ng| grep -v grep| awk '{print $5}&quot;`
  11
  12 if [[ $(pgrep -x espeak-ng) ]]
  13         then
  14                 case $status in
  15                         Tl) killall -s CONT espeak-ng;;
  16                         Sl) killall -s STOP espeak-ng;;
  17                 esac
  18         else
  19                 xsel | espeak-ng -v mb-us3 -p3 -s135
  20 fi
  </code></pre>
  <p>I don't even know how to test the output of: <code>if [[ $(pgrep -x espeak-ng) ]]</code></p>
  <p>Can somebody help me to figure out what's wrong and give me some hints? Many thanks in advance.</p>