diff --git a/bin/solc b/bin/solc
index 95132dffe96bb4d81e1d98751bffd0c574ab8a1e..12b4bde57ce4d6a8a0291fc053b7a7b05b39d229 100755
--- a/bin/solc
+++ b/bin/solc
@@ -4,24 +4,68 @@
 
 # See if PATH is set up incorrectly (look for another install of this binary).
 
-mypath=$( realpath $0 )
-myname=${mypath##*/}
-for p in ${PATH//:/ }
-do
-    checkfile=${p}/${myname}
-    if [ -x ${checkfile} ]
+printf -v newline '\n'
+
+function find_evm_version()
+{
+    # Remember to set the evm version to be compatible with
+    # the blockchain. BFA is still at Byzantium (as per 2021).
+    # The current version is listed in lib/versions with
+    # keyword chain_evm_version
+    unset evmvers
+    local keyword
+    keyword=chain_evm_version
+    while read -r
+    do
+        if [[ "$REPLY" =~ ^${keyword}= ]]
+        then
+            evmvers=${REPLY#${keyword}=}
+            break
+        fi
+    done < "${BFAHOME:-/home/bfa/bfa}/lib/versions"
+    if [ -z "$evmvers" ]
     then
-        if [ $( realpath ${checkfile} ) = $mypath ]
+        printf -v errortxt '%s\n%s' "$errortxt" "Can not find the keyword ${keyword} in lib/versions"
+        errortxt=${errortxt#${newline}}
+    fi
+}
+
+function find_first_solc
+{
+    local mypath myname p
+    mypath=$( realpath "$0" )
+    myname=${mypath##*/}
+    unset first_solc
+    for p in ${PATH//:/ }
+    do
+        local checkfile=${p}/${myname}
+        if [ ! -x "${checkfile}" ]
+        then
+            continue
+        fi
+        if [ "$(realpath "${checkfile}")" = "$mypath" ]
         then
             continue
         fi
         # we found another one, yay!
-        evmvers=$( grep '^chain_evm_version=' ${BFAHOME:-/home/bfa/bfa}/lib/versions | head -1 )
-        exec ${checkfile} ${evmvers/*=/--evm-version=} --combined-json abi,asm,ast,bin,bin-runtime,compact-format,devdoc,generated-sources,generated-sources-runtime,hashes,interface,metadata,opcodes,srcmap,srcmap-runtime,storage-layout,userdoc "$@"
-        exit 1
+        first_solc=${checkfile}
+        break
+    done
+    if [ -z "$first_solc" ]
+    then
+        printf -v errortxt '%s\n%s' "$errortxt" "solc: command not found."
+        errortxt=${errortxt#${newline}}
     fi
-done
+}
+
+errortxt=
+find_first_solc
+find_evm_version
+if [ -n "$errortxt" ]
+then
+    echo "$errortxt" >&2
+    exit 1
+fi
 
-# not found
-echo "solc: command not found." >&2
+exec "${first_solc}" --evm-version="$evmvers" --combined-json abi,asm,ast,bin,bin-runtime,compact-format,devdoc,generated-sources,generated-sources-runtime,hashes,interface,metadata,opcodes,srcmap,srcmap-runtime,storage-layout,userdoc "$@"
 exit 1