When I run this command:
cat output | grep -i state | sort | uniq | awk '{print $ 3}')
the output is:
00x1
00x5
0080
To assign them to an array, I did this:
STATUS_ARRAY=($(cat output | grep -i state | sort | uniq | awk '{print $ 3}'))
but it didn't work. For every, system the output of that command is different and I want to check every single one of them.
For example -- there are 21 types of status! -- this code:
for STATUS in "${STATUS_ARRAY=[@]}"
do
if [ "$STATUS" == '00x1' ] && [ "$STATUS" == '00x5' ];
then
echo " everything is normal"
else [ "$STATUS" == '0080' ];
echo " check your system "
fi
done
but when array doesn't work it won't return anything. What is wrong with this?
The contents of output
are:
State = 00x1
State = 00x5
State = 0080
"${STATUS_ARRAY[@]}"
. Don't capitalize normal variables. By convention only environment variables are in capitalsoutput
? Also did you read my comment regarding"${STATUS_ARRAY[@]}"
? See there is no=
sign in there. If you want to know more about arrays,readarray
ormapfile
see mywiki.wooledge.org/BashFAQ/005