Skip to content

Instantly share code, notes, and snippets.

@BigCedar
BigCedar / array_diff.sh
Last active November 11, 2023 16:12
Bash: find non common elements between two arrays
#!/bin/bash
list1=("l" "o" "s" "W" "i" "e" "n")
list2=("l" "o" "s" "e")
diff_list=()
common_list=()
#loop through the first list comparing an item from list1 with every item in list2
for i in "${!list1[@]}"; do
#begin looping through list2
for x in "${!list2[@]}"; do
#compare the two items