Forrest logo
back to the test tool

test:tldr:89351

test: Test if a given variable is equal to a given string.
$ test "${$MY_VAR}" == "${-bin-zsh}"
try on your machine

This command compares two variables to check if they have the same value. Let's break it down:

  • test is a command used to evaluate conditions. In this case, it is checking for equality between two variables.

  • ${$MY_VAR} is a variable expansion that first expands $MY_VAR and then expands the result of $MY_VAR as a variable itself. This can be interpreted as accessing the value of a variable named by the value of $MY_VAR.

  • ${-bin-zsh} is a variable, likely representing some value like bin-zsh.

  • == is the equality operator used to compare the two sides of the expression.

Putting it all together, the command checks if the value of the nested variable ${$MY_VAR} is equal to the value of the variable ${-bin-zsh}. If they are equal, the test is successful and returns a true value. If they are not equal, the test fails and returns a false value.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the test tool