0

I couldn't get the result I wanted when I used if[..] in the if structure in bash script. I was told to use if[[..]] but the reason was not explained. What is the difference if[..] and if[[..]] ?

Example;

while true; do
...
...
...


            if [[ $warn = "error" ]]
            then
...
...
...
brkshn
  • 1
  • You don't _need_ them. – KamilCuk Sep 15 '21 at 09:53
  • 1
    Cross-site duplicate: [What is the difference between the Bash operators [[ vs [ vs ( vs ((?](https://unix.stackexchange.com/q/306111/118235) – Benjamin W. Sep 15 '21 at 09:54
  • 2
    @brkshn : It depends what functionality you need. After `if` can come any command - only the exit code matters. I tend to use `[[` or `((`, because they are more flexible than `[`, but it's a matter of taste. But your question is misleading: You are talking about `if[` and `if[[`, and both are nonsense. Correct would be `if [` or `if [[`. Be more careful with spacing, or it will bite you one day! – user1934428 Sep 15 '21 at 11:24

0 Answers0