Skip to main content
added 14 characters in body
Source Link
glenn jackman
  • 248.6k
  • 42
  • 233
  • 362
  1. The processSnapshot will always be empty: the ps output is going to the file

  2. when you pass the pattern as a variable, use the pattern match operator:

     findProcess=$( awk -v pname="$findProcessName" '$0 ~ pname' $tempFile )
    
  3. only use backticks when you need the output of a command. This rm $tempFile

     `rm $tempFile` 
    

    executes the rm command, returns the output back to the shell and, it the output is non-empty, the shell attempts to execute that output as a command.

     $ `echo foo`
     bash: foo: command not found
     $ `echo whoami`
     jackman
    

    Remove the backticks.

Of course, you don't need the temp file at all:

pgrep -fl $findProcessName
  1. The processSnapshot will always be empty: the ps output is going to the file

  2. when you pass the pattern as a variable, use the pattern match operator:

     findProcess=$( awk -v pname="$findProcessName" '$0 ~ pname' $tempFile )
    
  3. only use backticks when you need the output of a command. This rm $tempFile executes the rm command, returns the output back to the shell and, it the output is non-empty, the shell attempts to execute that output as a command. Remove the backticks.

Of course, you don't need the temp file at all:

pgrep -fl $findProcessName
  1. The processSnapshot will always be empty: the ps output is going to the file

  2. when you pass the pattern as a variable, use the pattern match operator:

     findProcess=$( awk -v pname="$findProcessName" '$0 ~ pname' $tempFile )
    
  3. only use backticks when you need the output of a command. This

     `rm $tempFile` 
    

    executes the rm command, returns the output back to the shell and, it the output is non-empty, the shell attempts to execute that output as a command.

     $ `echo foo`
     bash: foo: command not found
     $ `echo whoami`
     jackman
    

    Remove the backticks.

Of course, you don't need the temp file at all:

pgrep -fl $findProcessName
Source Link
glenn jackman
  • 248.6k
  • 42
  • 233
  • 362

  1. The processSnapshot will always be empty: the ps output is going to the file

  2. when you pass the pattern as a variable, use the pattern match operator:

     findProcess=$( awk -v pname="$findProcessName" '$0 ~ pname' $tempFile )
    
  3. only use backticks when you need the output of a command. This rm $tempFile executes the rm command, returns the output back to the shell and, it the output is non-empty, the shell attempts to execute that output as a command. Remove the backticks.

Of course, you don't need the temp file at all:

pgrep -fl $findProcessName