diff --git a/SOURCES/sudo.sh b/SOURCES/sudo.sh
new file mode 100644
index 0000000..7feaa8f
--- /dev/null
+++ b/SOURCES/sudo.sh
@@ -0,0 +1,41 @@
+#! /bin/bash
+
+# Emulate /usr/bin/sudo, so that SCL environment variables
+# are passed through via an /bin/env wrapper.
+# Includes work by Andy Fong <boringuy@gmail.com>
+
+cmd_started=false
+is_option_param_next=false
+for arg in "$@"
+do
+   case "$arg" in
+    *\'*)
+      arg= ;;
+   esac
+   if [ "$cmd_started" = true ]; then
+       cmd_options="$cmd_options '$arg'"
+   elif [ "$is_option_param_next" = true ]; then
+       sudo_options="$sudo_options $arg"
+       is_option_param_next=false
+   elif [[ $arg == -* ]]; then
+       sudo_options="$sudo_options $arg"
+       case "$arg" in
+        # all the options that take a parameter
+        "-g" | "-h" | "-p" | "-u" | "-U" | "-C" | "-s" | "-r" | "-t" | "-T")
+            is_option_param_next=true
+        ;;
+        "--")
+          cmd_started=true
+        ;;
+       esac
+   elif [[ $arg == *=* ]]; then
+       sudo_options="$sudo_options $arg"
+   else
+       cmd_options="$cmd_options '$arg'"
+       cmd_started=true
+   fi
+done
+if [ "$sudo_options" == "" ]; then
+    sudo_options="-E"
+fi
+exec /usr/bin/sudo $sudo_options env LD_LIBRARY_PATH=$LD_LIBRARY_PATH PATH=$PATH scl enable %{scl} "$cmd_options"
diff --git a/SPECS/gcc-toolset-9.spec b/SPECS/gcc-toolset-9.spec
index dd10b18..d56492f 100644
--- a/SPECS/gcc-toolset-9.spec
+++ b/SPECS/gcc-toolset-9.spec
@@ -5,11 +5,12 @@
 Summary: Package that installs %scl
 Name: %scl_name
 Version: 9.0
-Release: 3%{?dist}
+Release: 4%{?dist}
 License: GPLv2+
 Group: Applications/File
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 Source0: README
+Source1: sudo.sh
 
 # The base package requires just the toolchain and the perftools.
 Requires: %{scl_prefix}toolchain %{scl_prefix}perftools
@@ -103,9 +104,6 @@ export PATH=%{_bindir}\${PATH:+:\${PATH}}
 export MANPATH=%{_mandir}:\${MANPATH}
 export INFOPATH=%{_infodir}\${INFOPATH:+:\${INFOPATH}}
 export PCP_DIR=%{_scl_root}
-# Some perl Ext::MakeMaker versions install things under /usr/lib/perl5
-# even though the system otherwise would go to /usr/lib64/perl5.
-export PERL5LIB=%{_scl_root}/%{perl_vendorarch}:%{_scl_root}/usr/lib/perl5:%{_scl_root}/%{perl_vendorlib}\${PERL5LIB:+:\${PERL5LIB}}
 # bz847911 workaround:
 # we need to evaluate rpm's installed run-time % { _libdir }, not rpmbuild time
 # or else /etc/ld.so.conf.d files?
@@ -116,28 +114,13 @@ if [ "\$rpmlibdir" != "\${rpmlibdir/lib64/}" ]; then
 fi
 export LD_LIBRARY_PATH=%{_scl_root}\$rpmlibdir\$rpmlibdir32\${LD_LIBRARY_PATH:+:\${LD_LIBRARY_PATH}}
 export LD_LIBRARY_PATH=%{_scl_root}\$rpmlibdir\$rpmlibdir32:%{_scl_root}\$rpmlibdir/dyninst\$rpmlibdir32/dyninst\${LD_LIBRARY_PATH:+:\${LD_LIBRARY_PATH}}
-# duplicate python site.py logic for sitepackages
-pythonvers=`python3 -c 'import sys; print (sys.version[:3])'`
-export PYTHONPATH=%{_prefix}/lib64/python\$pythonvers/site-packages:%{_prefix}/lib/python\$pythonvers/site-packages\${PYTHONPATH:+:\${PYTHONPATH}}
 export PKG_CONFIG_PATH=%{_libdir}/pkgconfig\${PKG_CONFIG_PATH:+:\${PKG_CONFIG_PATH}}
 EOF
 
 # Sudo script
 # ===========
-cat <<EOF >sudo
-#! /bin/sh
-# TODO: parse & pass-through sudo options from \$@
-sudo_options="-E"
-
-for arg in "\$@"
-do
-   case "\$arg" in
-    *\'*)
-      arg=`echo "\$arg" | sed "s/'/'\\\\\\\\''/g"` ;;
-   esac
-   cmd_options="\$cmd_options '\$arg'" 
-done
-exec /usr/bin/sudo \$sudo_options LD_LIBRARY_PATH=\$LD_LIBRARY_PATH PATH=\$PATH scl enable %{scl} "\$cmd_options"
+cat <<'EOF' > sudo
+%{expand:%(cat %{SOURCE1})}
 EOF
 
 # " (Fix vim syntax coloring.)
@@ -203,6 +186,10 @@ if [ $1 = 0 ]; then
 fi
 
 %changelog
+* Wed Nov 20 2019 Marek Polacek <polacek@redhat.com> - 9.0.4
+- implement better sudo wrapper (#1774118)
+- drop setting PYTHONPATH and PERL5LIB
+
 * Tue Aug 27 2019 Marek Polacek <polacek@redhat.com> - 9.0.3
 - require dyninst on ppc64le and aarch64 (#1746085)