Skip to content

Instantly share code, notes, and snippets.

@josepsmartinez
Created April 16, 2021 15:43
Show Gist options
  • Save josepsmartinez/aa920fc6aa0162a7a7c010d58c1282fe to your computer and use it in GitHub Desktop.
Save josepsmartinez/aa920fc6aa0162a7a7c010d58c1282fe to your computer and use it in GitHub Desktop.
Calling Bash functions with sudo
#!/bin/bash
# Adapted from (https://unix.stackexchange.com/a/269080/388950)
no_sudo_func () {
apt update
}
F=$(declare -f no_sudo_func)
sudo bash -c "$F; no_sudo_func"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment