0
if [ $(stat -c %s $OTDEFERS) -gt 128 ] ; then
   echo
   echo WARNING: Records have been written to the defers file
   STEP_WARNING=1
fi

I'm getting the following error when running this script:

-gt: unary operator expected

I read that putting the variables in double quotes usually does the job but how would it work with a variable that is contained within brackets?

  • Welcome on U&L! Have you any reason to think that quoting variables within "brackets" might not work as expected? (`[` is by default a command: from the quoting point of view, `[ "$var" ...` works the same way as `echo "$var" ...`). – fra-san May 29 '19 at 10:36
  • Hi! Thanks for the answer. When I put double quotes around the brackets like this "$(stat -c %s $OTDEFERS)" it turns into a string – MLansky May 29 '19 at 10:52
  • Uhm... no, double quotes around command substitution (`$(...)`) won't make it a fixed string. Single quotes would. See, for reference: [What is the difference between “…”, '…', $'…', and $“…” quotes?](https://unix.stackexchange.com/q/503013/315749). Also, `stat -c %s` returns a single number (or nothing), thus preventing split+glob of the result of `$(...)` is likely not necessary. What you need to double-quote is `$OTDEFERS` → `"$OTDEFERS"`. – fra-san May 29 '19 at 11:07
  • I've tried double quoting "$OTDEFERS" but I'm getting the same error.. – MLansky May 29 '19 at 11:10
  • 1
    Probably because `"$OTDEFERS"` does not expand to a valid path. Are you getting other error messages (e.g. `stat: cannot stat : No such file or directory`)? – fra-san May 29 '19 at 11:18
  • can you share which type shell you are trying(bash, sh etc)? – asktyagi May 29 '19 at 13:09

0 Answers0