-1

Why is this not working please help ! Why is the pwd in the code not working , both scripts are in the same file Here is the code :

check_process() {
  echo "$ts: checking $1"
  [ "$1" = "" ]  && return 0
  [ `pgrep -n $1` ] && return 1 || return 0
}
parent_path=$( pwd )
while [ 1 ]; do
  # timestamp
  ts=`date +%T`

  echo "$ts: begin checking..."
  check_process "SlimeRancher"
  [ $? -eq 0 ] && echo "$ts: not running"
  [ $? -eq 1 ] && echo "$ts: it is running" && 'bash $parent_path+"/.forcequit.sh"'
  sleep 5
done
7mo0ode2
  • 21
  • 1
  • 4
  • 1
    The `[ $? -eq 1 ]` only happens to work because of a lucky coincidence. You are examining the exit code of the previous command, which in this case is `[ $? -eq 0 ]`. Anyway, ths proper way to write that is `if checkprocess "SlimeRancher"; then ... else ...; fi`. – tripleee Jan 16 '16 at 17:16
  • There are several other errors in this code which http://shellcheck.net/ would catch. – Charles Duffy Jan 16 '16 at 17:34

1 Answers1

2

pwd is not your problem; you are single-quoting a string that should be left unquoted.

[ $? -eq 1 ] && echo "..." && bash "$parent_path"/.forcequit.sh
chepner
  • 497,756
  • 71
  • 530
  • 681