I am new to writing code/scripts, please forgive me if this is a question that is simple. I have searched the site and not found the answer to fix my problem. I am trying to use $SerialOutput
in the rest of the script but it is coming back {}
. When I do a shellcheck
on it it states the following
In Output_Test.sh line 12:
SerialOutput="$SerialOutput\n v$version $serial"
^-- SC2030: Modification of SerialOutput is local (to subshell caused by pipeline).
In Output_Test.sh line 14:
echo "{$SerialOutput}"
^-- SC2031: SerialOutput was modified in a subshell. That change might be lost.
Can anyone help clarify what I am doing wrong? Below is the script in question.
#!/bin/sh
if [ -d "/Library/Preferences/VMware Fusion/" ] ; then
result=$(grep -iH Serial /Library/Preferences/VMware\ Fusion/license* | awk '{print $2 $4}' | sed 's/"//g')
echo "$result" | while read -r a;
do
version=$(echo "$a" | cut -d "-" -f 3)
serial=$(echo "$a" | cut -d ":" -f 2 | sed 's/Serial//g')
SerialOutput="$SerialOutput\n v$version $serial"
done
else
echo "{NA}"
fi
echo "{$SerialOutput}"