'For loop Bash Scripting with If Else character [closed]

#!/bin/bash
for i in "abc" "efg" "lmn" 
do
    for j in 9 7 3 "lmn" 
    do
        if (( $j==$i ))
        then
            echo $i
        fi
    done

done

Expected Output: lmn

Output: abc efg lmn



Solution 1:[1]

You have to use square brackets [] and not ()

#!/bin/bash
for i in "abc" "efg" "lmn" 
do
    for j in 9 7 3 "lmn" 
    do
        if [[ $j == $i  ]]
        then
            echo $i
        fi
    done

done

the above works

Output:

lmn

The reason for using [] is clearly explained in this post

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 error404