I get a syntax error when using the following if condition in a bash script.
if [ -f $pid_file ] && [ $check_run_proc == *"my_proc"* ] && kill -0 $(cat "$pid_file"); then
Can you please identify what the problem is?
Thank you.
You need to use bash's [[
special word and the =~
operator to match regular expressions. That if
-clause should do it:
if [ -f "$pid_file" ] && [[ "$check_run_proc" =~ "my_proc" ]] &&
kill -0 $(cat "$pid_file"); then
*
?