I am currently attempting to create a bash script that will check inside of each users /Library/Mail folder to see if a folder named V2 exists. The script should create an array with each item in the array being a user and then iterate through each of these users checking their home folder for the above captioned contents. This is what I have so far:
#!/bin/bash
cd /Users
array=($(ls))
for i in ${array[@]}
do
if [ -d /$i/Library/Mail/V2 ]
then
echo "$i mail has been upgraded."
else
echo "$i FAIL"
fi
done
Populating your array from the output of
lsis going to make for serious problems when you have a username with spaces. Use a glob expression instead. Also, using[ -d $i/... ]will similarly break on names with spaces — either use[[ -d $i/... ]](the[[ ]]construct has its own syntax rules and doesn’t require quoting) or[ -d "$i/..." ](with the quotes).Similarly, you need to double-quote
"${array[@]}"to avoid string-splitting from splitting names with spaces in two, as follows:That said, you don’t really need an array here at all: