Sample Header Ad - 728x90

How do I test if an item is in a bash array?

34 votes
7 answers
180131 views
Help for a simple script #!/bin/bash array1=( prova1 prova2 slack64 ) a="slack64" b="ab" if [ $a = $b ] then echo "$a = $b : a is equal to b" else echo "$a = $b: a is not equal to b" fi --- This script simply doesn't work, I want a script which check if slack64 is present in a list(i use an array),and simply give me, yes is present,or no. I don't know how to compare an array with a single variable.
Asked by elbarna (13690 rep)
Jan 3, 2015, 02:02 AM
Last activity: Jan 14, 2025, 01:48 PM