Created
April 16, 2021 15:43
-
-
Save josepsmartinez/aa920fc6aa0162a7a7c010d58c1282fe to your computer and use it in GitHub Desktop.
Calling Bash functions with sudo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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