1

I ran into an error in the first line of the following bash shell script when parsing.

  if [[ -v VAR_1 ]]; then
    VAR_2="$VAR_1/sub_folder"
  fi

This script works fine on my colleague's Linux machine in Bash shell, but failed on my Macbook MacOS.

The error message is

conditional binary operator expected
Hui Zheng
  • 2,394
  • 1
  • 14
  • 18
  • 2
    The version of bash that comes with macOS i (v3.2.57) is too old to support the -v test (it wasn't added until v4.2). See ["How to check if a variable is set in Bash"](https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash) for alternate methods that will work in older versions (as well as other shells). – Gordon Davisson Jan 25 '23 at 22:51

0 Answers0