Reputation: 454
I have an associative array that holds filenames. I'd like to use cmp on them to see if they differ from each other.
declare -A configfiles
configfiles["file1"]="file2"
for k in "${!configfiles[@]}"
do
if cmp $k $configfiles[$k]; then
echo Do something
fi
done
Bash returns: cmp: [file1]: No such file or directory
How can I get bash to omit the brackets while calling cmp?
Upvotes: 0
Views: 150
Reputation: 531055
You need to use the correct syntax for accessing array elements:
if cmp "$k" "${configfiles[$k]}"; then
Upvotes: 1