We can infer the cluster DBR version using the env $DATABRICKS_RUNTIME_VERSION. (For the exact spark/scala version mapping, you can refer to the specific DBR release notes)
Sample usage inside a init script,
DBR_10_4_VERSION="10.4"
if [[ "$DATABRICKS_RUNTIME_VERSION" == "$DBR_10_4_VERSION"* ]]; then
echo "running 10.4 specific commands"
else
echo "Skipping 10.4 specific commands"
fi