Skip to content

Instantly share code, notes, and snippets.

@jubalfh
Created March 19, 2014 12:27
Show Gist options
  • Save jubalfh/9640641 to your computer and use it in GitHub Desktop.
Save jubalfh/9640641 to your computer and use it in GitHub Desktop.
run_as() {
local uid newuid bash_argv
read -r newuid <<< "$1"
read -r bash_argv <<< "${BASH_ARGV[@]}"
uid="$(id -nu)"
if [[ "${uid}" == "root" ]]; then
exec su - "${newuid}" -s /bin/bash -c "$0 ${bash_argv}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment