title: Brackets [ ] around string with grep and ps - ef
body: <p>I am trying to get the time of the process start. 
  Usually I use the brackets on the first letter of the process that I am running. 
  It takes away the self reporting "grep" in the ps output. </p>
  
  <pre><code>#!/bin/bash
  
  set -x
  restarTXG="sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STR_PS"
  bounceTXG="sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STP_PS; sleep 10 ; sendevent -E FORCE_STARTJOB -J CASPERRT_CD_TXG_DR_STR_PS"
  timeofTXG=$(ps -ef | grep [t]xg | awk '{print $5}' )
  
  if [ -n "$timeofTXG" ] ; then
      printf "%s\n" "The TXG_DR is ON as of $timeofTXG"
  else
      printf "%s\n" "'The TXG_DR is OFF"
  fi 
  </code></pre>
  
  <p>18:40 is the time I run the check script.  17:44 is the time the process started.     </p>
  
  <pre><code>++ ps -ef
  ++ grep '[t]xg'
  ++ awk '{print $5}'
  + timeofTXG='17:44
  18:40
  18:40'
  + '[' -n '17:44
  18:40
  18:40' ']'
  + printf '%s\n' 'The TXG_DR is ON as of 17:44
  18:40
  18:40'
  The TXG_DR is ON as of 17:44
  18:40
  18:40
  </code></pre>
  
  <p>I don't really know how the square brackets work.   When I run the ps from the command line, the [] brackets do work -- ps -ef | grep [t]xg | awk '{print $5}'
  however in the context of the bash script, they are not working, they are giving me the time of the self reporting grep. 
  How do the brackets work?  Why do they work on the command line and not in the script?   How do I get rid of the self revealing grep in bash script ?</p>