0

I want to check if the variable is equal to the true keyword and if it is then do something accordingly but it is behaving in an undefined way. don't get what I want its a simple question but thank you : >

STRICT=$false

if [ "$STRICT" == $true ] # i am not sure about this line what should i do
  then  
  FS="${FS} hey"
fi
5
  • 3
    Do you have variables named true and false? Commented Dec 15, 2021 at 23:13
  • 2
    There are no boolean keywords in shell. $false expands to the value of the (presumably undefined) variable false. Commented Dec 15, 2021 at 23:14
  • 1
    You might have a misunderstanding about true and false since you're calling it keyword. Consider taking a look at this page about a boolean Commented Dec 15, 2021 at 23:15
  • thanks everyoen i had know idea about that i could use true directly Commented Dec 15, 2021 at 23:15
  • 1
    You can use true directly because it's just a regular string. There is no boolean type in shell, and so no true and false values. Commented Dec 15, 2021 at 23:16

1 Answer 1

3

Just use strings true and false, not variables.

STRICT=false

if [ "$STRICT" = true ]
then  
  FS="${FS} hey"
fi

And the standard string comparison operator is =. == is a bash extension.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.