(This is debian squeeze amd64)
I need to check if the file is a member of the file list. So far, my (test) script:
set -x
array=$( ls )
echo $array
FILE=log.out
if $FILE in $array
then echo "success!"
else echo "bad!"
fi
exit 0
¿Any ideas?
Thanks for all the answers. To clarify: the script below is just an example, the actual problem is more complicated. In the final solution, this will be done in a loop, so I need the file (name) to be checked in order to be in a variable.
Thanks again. There is no my test - the script works and reads:
in_list() {
local search="$1"
shift
local list=("$@")
for file in "${list[@]}" ; do
[[ "$file" == "$search" ]] && return 0
done
return 1
}
array=( * )
FILE="log.out"
if in_list "$FILE" "${array[@]}"
then echo "success!"
else echo "bad!"
fi
exit 0
source
share