vendredi 13 août 2021

`[ "$(...)" = *FAIL* ]` not working in POSIX sh script

Here's a sample from .sh script:

#!/bin/sh

........

if [ "$(tail -n 1 log_file.txt)" = *"FAIL"* ]; then
  exit 1
else
  # some command here
  exit 0
fi

It must match last line of some file with pattern "FAIL" and if result of matching is true return exit code 1 otherwise 0.

In this case script is always terminated with exit code 0 even for those strings that don't contain FAIL substring. Please help me to fix if statement.

P.S. shebang must be #!/bin/sh not #!/bin/bash

Aucun commentaire:

Enregistrer un commentaire